尧图网络 高端网站定制 · 原创设计
免费咨询热线
400-888-6620
免费获取方案
Ubuntu20.04 Server初始化
Ubuntu20.04 Server初始化1. 命令提示符的修改rootubuntu2004:~# vim ~/.bashrc#在配置文件结尾添加以下内容PS1\[\e[1;33m\][\u\h \W]\$\[\e[0m\]#修改命令提示符的颜色为黄色exportHISTTIMEFORMAT%F %T #指定history时间格式exportEDITORvim#指定文本编辑器rootubuntu2004:~# . ~/.bashrc #让.bashrc配置文件生效2. 清空防火墙规则#Ubuntu20.04 Server默认没有开启防火墙但是默认安装了ufw防火墙推荐使用iptables防火墙[rootubuntu2004 ~]#ufw status #查看ufw防火墙状态Status: inactive[rootubuntu2004 ~]#ufw disable #关闭ufw防火墙Firewall stopped and disabled on system startup[rootubuntu2004 ~]#apt remove ufw #卸载ufw[rootubuntu2004 ~]#apt purge ufw #删除ufw依赖包[rootubuntu2004 ~]#whereis iptables #查看iptables文件的位置iptables: /usr/sbin/iptables /usr/share/iptables /usr/share/man/man8/iptables.8.gz[rootubuntu2004 ~]#dpkg -s iptables #列出iptables包的状态包括详细信息Package: iptables Status:installok installed Priority: optional Section: net Installed-Size:2639Maintainer: Ubuntu Developersubuntu-devel-discusslists.ubuntu.comArchitecture: amd64 Multi-Arch: foreign Version:1.8.4-3ubuntu2#启动iptables[rootubuntu2004 ~]#modprobe ip_tables#清空iptables防火墙规则[rootubuntu2004 ~]#iptables -F[rootubuntu2004 ~]#iptables -vnLChain INPUT(policy ACCEPT314packets,22966bytes)pkts bytes target prot optinoutsourcedestination Chain FORWARD(policy ACCEPT0packets,0bytes)pkts bytes target prot optinoutsourcedestination Chain OUTPUT(policy ACCEPT233packets,23322bytes)pkts bytes target prot optinoutsourcedestination3. 修改网卡名#修改配置文件为下面形式[rootubuntu2004 ~]#vim /etc/default/grubGRUB_CMDLINE_LINUXnet.ifnames0#或者sed修改#方法一替换[rootubuntu2004 ~]#sed -i.bak /^GRUB_CMDLINE_LINUX/c GRUB_CMDLINE_LINUXnet.ifnames0 /etc/default/grub#方法二搜索替换[rootubuntu2004 ~]#sed -i.bak /^GRUB_CMDLINE_LINUX/s#$#net.ifnames0# /etc/default/grub[rootubuntu2004 ~]#grep ^[a-Z] /etc/default/grubGRUB_DEFAULT0GRUB_TIMEOUT_STYLEhiddenGRUB_TIMEOUT0GRUB_DISTRIBUTORlsb_release-i-s2/dev/null||echoDebianGRUB_CMDLINE_LINUX_DEFAULTmaybe-ubiquityGRUB_CMDLINE_LINUXnet.ifnames0#生成新的grub.cfg文件[rootubuntu2004 ~]#grub-mkconfig -o /boot/grub/grub.cfg#重启生效[rootubuntu2004 ~]#reboot4. 配置静态IP[rootubuntu2004 ~]#vim /etc/netplan/01-netcfg.yaml# This file describes the network interfaces available on your system# For more information, see netplan(5).network: version:2renderer: networkd ethernets: eth0: addresses:[10.0.0.151/24]gateway4:10.0.0.2 nameservers: addresses:[223.5.5.5,180.76.76.76,8.8.8.8]#修改网卡配置文件后需执行命令生效[rootubuntu2004 ~]#netplan apply#查看IP[rootubuntu2004 ~]#ip a1: lo:LOOPBACK,UP,LOWER_UPmtu65536qdisc noqueue state UNKNOWN group default qlen1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet127.0.0.1/8 scopehostlo valid_lft forever preferred_lft forever inet6 ::1/128 scopehostvalid_lft forever preferred_lft forever2: eth0:BROADCAST,MULTICAST,UP,LOWER_UPmtu1500qdisc fq_codel state UP group default qlen1000link/ether 00:0c:29:88:18:c6 brd ff:ff:ff:ff:ff:ff inet10.0.0.151/24 brd10.0.0.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe88:18c6/64 scopelinkvalid_lft forever preferred_lft forever#查看gateway[rootubuntu2004 ~]#route -nKernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface0.0.0.010.0.0.20.0.0.0 UG000eth010.0.0.00.0.0.0255.255.255.0 U000eth0#查看DNS[rootubuntu1804 ~]#systemd-resolve --status[rootubuntu2004 ~]#resolvectl status ##Ubuntu 20.04新命令Global LLMNR setting: no MulticastDNS setting: no DNSOverTLS setting: no DNSSEC setting: no DNSSEC supported: no DNSSEC NTA:10.in-addr.arpa16.172.in-addr.arpa168.192.in-addr.arpa17.172.in-addr.arpa18.172.in-addr.arpa19.172.in-addr.arpa20.172.in-addr.arpa21.172.in-addr.arpa22.172.in-addr.arpa23.172.in-addr.arpa24.172.in-addr.arpa25.172.in-addr.arpa26.172.in-addr.arpa27.172.in-addr.arpa28.172.in-addr.arpa29.172.in-addr.arpa30.172.in-addr.arpa31.172.in-addr.arpa corp d.f.ip6.arpa home internal intranet lanlocalprivatetestLink2(eth0)Current Scopes: DNS DefaultRoute setting:yesLLMNR setting:yesMulticastDNS setting: no DNSOverTLS setting: no DNSSEC setting: no DNSSEC supported: no Current DNS Server:223.5.5.5 DNS Servers:223.5.5.5180.76.76.768.8.8.85. 关闭SELinux[rootubuntu2004 ~]#apt update[rootubuntu2004 ~]#apt -y install selinux-utils selinux[rootubuntu2004 ~]#getenforce #获取selinux当前状态Disabled[rootubuntu2004 ~]#vim /etc/selinux/configSELINUXdisabled[rootubuntu2004 ~]#reboot #重启生效6. 实现邮件通信[rootubuntu2004 ~]#apt install -y postfix bsd-mailx[rootubuntu2004 ~]#systemctl enable --now postfix# 邮件配置文件/etc/mail.rc7. 配置apt源[rootubuntu2004 ~]#vim /etc/apt/sources.list[rootubuntu2004 ~]#grep ^[a-Z] /etc/apt/sources.listdeb https://mirrors.aliyun.com/ubuntu/ focal main restricted deb https://mirrors.tencent.com/ubuntu/ focal main restricted deb https://mirrors.huaweicloud.com/ubuntu/ focal main restricted deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted deb https://mirrors.tencent.com/ubuntu/ focal-updates main restricted deb https://mirrors.huaweicloud.com/ubuntu/ focal-updates main restricted deb https://mirrors.aliyun.com/ubuntu/ focal universe deb https://mirrors.tencent.com/ubuntu/ focal universe deb https://mirrors.huaweicloud.com/ubuntu/ focal universe deb https://mirrors.aliyun.com/ubuntu/ focal-updates universe deb https://mirrors.tencent.com/ubuntu/ focal-updates universe deb https://mirrors.huaweicloud.com/ubuntu/ focal-updates universe deb https://mirrors.aliyun.com/ubuntu/ focal multiverse deb https://mirrors.tencent.com/ubuntu/ focal multiverse deb https://mirrors.huaweicloud.com/ubuntu/ focal multiverse deb https://mirrors.aliyun.com/ubuntu/ focal-updates multiverse deb https://mirrors.tencent.com/ubuntu/ focal-updates multiverse deb https://mirrors.huaweicloud.com/ubuntu/ focal-updates multiverse deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse deb https://mirrors.tencent.com/ubuntu/ focal-backports main restricted universe multiverse deb https://mirrors.huaweicloud.com/ubuntu/ focal-backports main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted deb https://mirrors.tencent.com/ubuntu/ focal-security main restricted deb https://mirrors.huaweicloud.com/ubuntu/ focal-security main restricted deb https://mirrors.aliyun.com/ubuntu/ focal-security universe deb https://mirrors.tencent.com/ubuntu/ focal-security universe deb https://mirrors.huaweicloud.com/ubuntu/ focal-security universe deb https://mirrors.aliyun.com/ubuntu/ focal-security multiverse deb https://mirrors.tencent.com/ubuntu/ focal-security multiverse deb https://mirrors.huaweicloud.com/ubuntu/ focal-security multiverse[rootubuntu2004 ~]#apt update8. chrony时间同步#服务器端配置[rootcentos7 ~]#hostname -I10.0.0.7[rootcentos7 ~]#yum -y install chrony[rootcentos7 ~]#vim /etc/chrony.confserver ntp.aliyun.com iburst server ntp1.aliyun.com iburst server ntp2.aliyun.com iburst server ntp3.aliyun.com iburst#allow 192.168.0.0/16allow0.0.0.0/0#加此行,指定允许同步的网段# Serve time even if not synchronized to a time source.localstratum10#删除此行注释,当互联网无法连接,仍然可以为客户端提供时间同步服务[rootcentos7 ~]#systemctl restart chronyd#服务启动后会打开端口123/udp[rootcentos7 ~]#ss -ntluNetid State Recv-Q Send-Q Local Address:Port Peer Address:Port udp UNCONN00*:123 *:* udp UNCONN00127.0.0.1:323 *:* udp UNCONN00[::1]:323[::]:* tcp LISTEN0100127.0.0.1:25 *:* tcp LISTEN0128*:22 *:* tcp LISTEN0100[::1]:25[::]:* tcp LISTEN0128[::]:22[::]:*#客户端配置[rootubuntu2004 ~]#hostname -I10.0.0.151[rootubuntu2004 ~]#apt install -y chrony[rootubuntu2004 ~]#vim /etc/chrony/chrony.confpool10.0.0.7 iburst[rootubuntu2004 ~]#systemctl restart chronyd.service#客户端确认同步成功[rootubuntu2004 ~]#chronyc sources -v210Number of sources1.-- Source mode^server,peer,#localclock. / .- Source state*current synced,combined ,-not combined,|/?unreachable,xtimemay beinerror,~timetoo variable.||.- xxxx[yyyy]/- zzzz||Reachability register(octal)-.|xxxxadjusted offset,||Log2(Polling interval)--.||yyyymeasured offset,||\||zzzzestimated error.||||\MS Name/IP address Stratum Poll Reach LastRx Last sample^*10.0.0.736171433us[114us]/- 35ms9 . shell脚本自动加注释[rootubuntu2004 ~]#vim ~/.vimrc[rootubuntu2004 ~]#cat ~/.vimrcsetts4setexpandtabsetignorecase autocmd BufNewFile *.shexec:call SetTitle()func SetTitle()ifexpand(%:e)shcall setline(1,#!/bin/bash)call setline(2,#)call setline(3,#*************************************************************)call setline(4,#Author: chen)call setline(5,#QQ: 2088346053)call setline(6,#Date: .strftime(%Y-%m-%d))call setline(7,#FileName: .expand(%))call setline(8,#Description: The test script)call setline(9,#Copyright (C): .strftime(%Y). All rights reserved)call setline(10,#*************************************************************)call setline(11,)endif endfunc autocmd BufNewFile * normal G[rootubuntu2004 ~]#. ~/.vimrc10. 修改时区[rootubuntu2004 ~]#timedatectlLocal time: Sat2022-07-2320:37:01 UTC Universal time: Sat2022-07-2320:37:01 UTC RTC time: Sat2022-07-2320:37:01 Time zone: Etc/UTC(UTC, 0000)System clock synchronized:yesNTP service: active RTCinlocalTZ: no[rootubuntu2004 ~]#timedatectl set-timezone Asia/Shanghai[rootubuntu2004 ~]#timedatectlLocal time: Sun2022-07-2422:48:09 CST Universal time: Sat2022-07-2320:48:09 UTC RTC time: Sat2022-07-2320:48:09 Time zone: Asia/Shanghai(CST, 0800)System clock synchronized:yesNTP service: active RTCinlocalTZ: no[rootubuntu2004 ~]#cat /etc/timezoneAsia/Shanghai[rootubuntu2004 ~]#vim /etc/default/localeLANGen_HK.UTF-8LANGUAGEen_HK:en[rootubuntu2004 ~]#reboot11. 设置允许root远程登录cloudubuntu2004:~$sudo-i[sudo]passwordforcloud:[rootubuntu2004 ~]#[rootubuntu2004 ~]#passwdNew password: Retype new password: passwd: password updated successfully[rootubuntu2004 ~]#[rootubuntu2004 ~]#vim /etc/ssh/sshd_configPermitRootLoginyes[rootubuntu2004 ~]#systemctl restart sshd.service
RELATED

相关推荐

AI模型推理容器化实战:优化部署与性能调优

AI模型推理容器化实战:优化部署与性能调优

1. AI模型推理容器化的核心挑战在真实生产环境中部署AI推理服务时,我们常遇到三个典型问题:首先是资源利用率波动大,白天请求高峰期GPU利用率能到70%,但夜间可能跌至10%以下;其次是环境依赖复杂,某次Tensor…

📅 2026/10/3 6:54:00
南大通用数据库-Gbase-8a-实战-绕过字段修改限制的四种曲线救国方案

南大通用数据库-Gbase-8a-实战-绕过字段修改限制的四种曲线救国方案

1. GBase 8a字段修改限制的核心痛点 第一次接触GBase 8a的开发者,往往会被它的字段修改限制惊到。这个国产MPP数据库在ALTER TABLE功能上确实有些"特立独行"——它不允许直接修改字段类型(varchar长度调整除外)、不能修改默认值、也…

📅 2026/10/25 23:12:21
【Java】IntelliJ IDEA 通过JDBC连接MySQL数据库实现数据增删改查

【Java】IntelliJ IDEA 通过JDBC连接MySQL数据库实现数据增删改查

1. 环境准备与项目创建在开始之前,我们需要确保开发环境已经准备就绪。首先,你需要安装以下软件:IntelliJ IDEA:推荐使用最新版本,社区版或旗舰版均可MySQL数据库:建议使用5.7或8.0版本JDK:Java…

📅 2026/10/16 20:03:33
MORE NEWS

更多资讯

📰

电工证科2最难的接线考试真题与备考技巧值不值得考

电工证科2最难的接线考试真题与备考技巧值不值得考 之前考的证在外省能不能转过来?这是很多在外地打工、打算返乡创业或准备在本地找工作的电工从业者最关心的问题。尤其是在河南信阳这样的地级市,很多中小施工企业负责人手里握着外省考来的电工证,但对本…

📰

鹤岗初级电工证怎么考?学历不高怕报不上名?这份上岗必备攻略全搞定

鹤岗初级电工证怎么考?学历不高怕报不上名?这份上岗必备攻略全搞定 学历不高怕报不上名?其实鹤岗初级电工证并不是只针对高学历人群,很多初中毕业甚至没上过学的工友都顺利拿下了。只要你愿意花点时间准备, 上岗必备…

📰

电工证共有几个等级保姆级教程:工地太忙根本没时间复习考试怎么办

电工证共有几个等级保姆级教程:工地太忙根本没时间复习考试怎么办 工地太忙根本没时间复习考试?别急,你不是一个人。很多刚入行的电工,尤其是第一次报考的,对电工证共有几个等级一无所知,甚至不知道从哪开始准备。今天我们就来帮你理清楚电工证的等级划…

📰

怎样考维修电工证呢网上查询外省证书能否转过来

怎样考维修电工证呢网上查询外省证书能否转过来 之前考的证在外省能不能转过来?这个问题在我们这行里可太常见了。很多小伙伴在外地打工,考了证却因为工作调动或回家乡发展,担心证件不能用,还得重新考。其实,现在网上查询已经很方便了,只要知道流程,外…

📰

零基础学习考电工证值不值得考?报名别被坑的全攻略

零基础学习考电工证值不值得考?报名别被坑的全攻略 你是不是也在犹豫要不要考电工证?怕被中介骗钱,怕流程太复杂,怕自己学不会?别急,这篇文章就是为你准备的,从报名到考试、从薪资到发展,全都给你讲明白, 零基础学习考电工证值不值得考…

📰

初级电工证证书样子多久拿证,学历不高也能考

初级电工证证书样子多久拿证,学历不高也能考 你是不是因为学历不高,一直担心自己报不了名?其实,初级电工证报考对学历要求非常低,基本上初中以上学历就可以报名了,完全不用担心学历问题。今天我们就来聊聊初级电工证证书的样子、多久拿证,还有它对咱们…

TODAY

今日更新

THIS WEEK

本周精选

THIS MONTH

本月热门

读完文章,想聊聊您的网站?

告诉我们您的行业与需求,资深顾问一对一梳理方案与报价,全程免费。

📞 💬