Ubuntu Server系统基础配置
1:更改主机名:
1 ~$ cat /etc/hostname 2 ubuntu-node.example.com
2:配置root远程登录
默认情况下,ubuntu不允许root用戶远程ssh,如果有实际场景需要允许root用戶远程ssh,则需要设置root密码,并且编辑/etc/ssh/sshd_config文件修改如下
~$ sudo vim /etc/ssh/sshd_config 32#PermitRootLogin prohibit-password #默认为禁止登录 33 PermitRootLogin yes#改为允许登录 57#PasswordAuthentication yes 58 PasswordAuthentication yes#打开密码认证,其实默认就是允许通过密码认证登录~ $ sudosu- root #切换到root用戶环境 ~# passwd #设置密码Enter new UNIX password:Retype new UNIX password: passwd: password updated successfully ~# systemctl restart sshd #重启ssh服务并测试root用戶远程ssh连接
3:更改网卡名称:eth*
如果没有在安装系统之前传递内核参数将网卡名称更改为eth*,则可以在安装系统之后使用以下方式修改
root@template-ubuntu-20200606:~# grep "^[a-Z]" /etc/default/grub GRUB_DEFAULT=0 GRUB_TIMEOUT_STYLE=hidden GRUB_TIMEOUT=2 GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` GRUB_CMDLINE_LINUX_DEFAULT="" GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0" #设置网卡名称
4:Ubuntu 18.04网络配置:
Ubuntu 从 17.10 开始,已放弃在 /etc/network/interfaces 里固定IP的配置,而是改成 netplan 方式,配置文件是:/etc/netplan/01-netcfg.yaml
ubuntu 17.04及之前的静态IP配置方式
~# cat /etc/network/interfaces root@molson:~# cat /etc/network/interfaces # interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback auto eth0 #网卡自启动,写自己要配置IP的实际网卡名称 iface eth0 inet static #配置静态IP,写自己要配置IP的实际网卡名称 address 172.18.3.12 #IP地址 netmask 255.255.0.0 #掩码 gateway 172.18.0.1 #网关 dns-nameservers 223.6.6.6 #DNS dns-nameservers 223.5.5.5 #重启网络服务 ~# /etc/init.d/networking restart ~# systemctl restart networking.service