一、修改ubuntu主机名
root@ubuntu1804:~# hostnamectl set-hostname ubuntu1804.magedu.orgroot@ubuntu1804:~# cat /etc/hostnameubuntu1804.magedu.org
root@ubuntu1804:~# hostnameubuntu1804.magedu.org
root@ubuntu1804:~# echo $HOSTNAME
ubuntu1804
root@ubuntu1804:~# exit
logout
wang@ubuntu1804:~$ sudo -iroot@ubuntu1804:~# echo $HOSTNAMEubuntu1804.magedu.org
二、修改网卡名
#修改配置文件为下面形式
root@ubuntu1804:~#vi /etc/default/grub
GRUB_CMDLINE_LINUX="net.ifnames=0"
#或者sed修改
root@ubuntu1804:~# sed -i.bak '/^GRUB_CMDLINE_LINUX=/s#"$#net.ifnames=0"#'
/etc/default/grub
#生效新的grub.cfg文件
root@ubuntu1804:~# grub-mkconfig -o /boot/grub/grub.cfg
#或者
root@ubuntu1804:~# update-grub
root@ubuntu1804:~# grep net.ifnames /boot/grub/grub.cfg
linux /vmlinuz-4.15.0-96-generic root=UUID=51517b88-7e2b-4d4a-8c14-
fe1a48ba153c ro net.ifnames=0linux /vmlinuz-4.15.0-96-generic root=UUID=51517b88-7e2b-4d4a-
8c14-fe1a48ba153c ro net.ifnames=0linux /vmlinuz-4.15.0-96-generic root=UUID=51517b88-7e2b-4d4a-
8c14-fe1a48ba153c ro recovery nomodeset net.ifnames=0linux /vmlinuz-4.15.0-76-generic root=UUID=51517b88-7e2b-4d4a-
8c14-fe1a48ba153c ro net.ifnames=0linux /vmlinuz-4.15.0-76-generic root=UUID=51517b88-7e2b-4d4a-
8c14-fe1a48ba153c ro recovery nomodeset net.ifnames=0#重启生效root@ubuntu1804:~# reboot
三、修改网卡配置文件
yaml的网卡配置文件有着严格的缩进,
root@ubuntu1804:~#vim /etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses: [192.168.8.10/24,10.0.0.10/8]
#或者用下面两行,两种格式不能混用
- 192.168.8.10/24
- 10.0.0.10/8
gateway4: 192.168.8.1
nameservers:
search: [magedu.com, magedu.org]
addresses: [180.76.76.76, 8.8.8.8, 1.1.1.1]
修改网卡配置文件之后执行命令生效:
root@ubuntu1804:~#netplan apply
查看IP和getway
root@ubuntu1804:~#ip addr
root@ubuntu1804:~#route -n
查看dns:
root@ubuntu1804:~#ls -l /etc/resolv.conflrwxrwxrwx 1 root root 39 Dec 12 11:36 /etc/resolv.conf ->../run/systemd/resolve/stub-resolv.conf
root@ubuntu1804:~# systemd-resolve --status
或者:
resolvectl dns
修改IP及配置路由:
root@ubuntu1804:~#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:
dhcp4: no
dhcp6: no
addresses: [10.0.0.18/16]
gateway4: 10.0.0.2
nameservers:
addresses: [223.6.6.6]
eth1:
dhcp4: no
dhcp6: no
addresses: [10.20.0.18/16]
routes:
- to: 10.30.0.0/16
via: 10.20.0.1
- to: 10.40.0.0/16
via: 10.20.0.1
- to: 10.50.0.0/16
via: 10.20.0.1
- to: 10.60.0.0/16
via: 10.20.0.1
root@ubuntu1804:~#netplan applyroot@ubuntu1804:~#route -nKernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.2 0.0.0.0 UG 0 0 0 eth0
10.0.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
10.20.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth1
10.30.0.0 10.20.0.1 255.255.0.0 UG 0 0 0 eth1
10.40.0.0 10.20.0.1 255.255.0.0 UG 0 0 0 eth1
10.50.0.0 10.20.0.1 255.255.0.0 UG 0 0 0 eth1
10.60.0.0 10.20.0.1 255.255.0.0 UG 0 0 0 eth1
也可以双网卡双文件:
#或者每个网卡各自一个配置文件
root@ubuntu1804:/etc/netplan# ls
01-netcfg.yaml 02-eth1.yaml
root@ubuntu1804:/etc/netplan# cat 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:
dhcp4: yesroot@ubuntu1804:/etc/netplan# cat 02-eth1.yaml
network:
version: 2renderer: networkdthernets:
eth1:
addresses:
- 10.20.0.11/16
- 192.168.0.11/24
gateway4: 10.0.0.2
nameservers:
search: [magedu.com, magedu.org]
addresses: [180.76.76.76, 8.8.8.8, 1.1.1.1]
routes:
- to: 10.30.0.0/16
via: 10.20.0.1
- to: 10.40.0.0/16
via: 10.20.0.1
- to: 10.50.0.0/16
via: 10.20.0.1
- to: 10.60.0.0/16
via: 10.20.0.1
标签:ubuntu1804,10.20,0.1,0.0,配置,网络,etc,ubuntu,root From: https://blog.51cto.com/gttwangyanjun/5841904