高版本的ubuntu采用netplan来管理网络
ubuntu从17.10开始,已放弃在/etc/network/interfaces里固定IP的配置,即使配置也不会生效,而是改成netplan方式 ,配置写在/etc/netplan/*.yaml的yaml文件里。 执行 netplan apply 命令可以让配置直接生效,放弃service networking restart方式重启网络。
ubuntu 18.04的server版本安装好以后,网络配置文件是:/etc/netplan/50-cloud-init.yaml
ubuntu 18.04的桌面版安装好以后,网络配置文件是:/etc/netplan/01-network-manager-all.yaml
(1)、ubuntu 18.04 桌面版
查看是服务器所装系统是否带桌面
# dpkg -l ubuntu-desktop
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-============-============-=================================
ii ubuntu-desktop 1.417 amd64 The Ubuntu desktop system
查看网络模式
检查是否安装了网络管理器
# dpkg -l network-manager
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-============-============-=================================
ii network-manage 1.10.6-2ubun amd64 network management framework (dae
检查X 服务器是否正在运行
# ps -e | grep X
864 tty1 00:00:00 Xwayland
2864 tty2 00:00:32 Xorg
查看当前安装的linux映像包信息,看是否包含“ server” ,包含server 说明当前系统是服务器版本,若没有那就是桌面版。
# dpkg --get-selections |grep linux-image
linux-image-4.15.0-20-generic install //最新的Ubuntu 18.04 桌面内核软件包
linux-image-generic //默认的桌面内核软件包
查看网卡配置采用的方式
# cat /etc/netplan/01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
查看ip的配置信息
# cat /etc/NetworkManager/system-connections/Wired\ connection\ 1
[connection]
id=Wired connection 1
uuid=11f23762-e4d4-3525-8a65-1b9dac25101c
type=ethernet
autoconnect-priority=-999
permissions=
timestamp=1548273764
[ethernet]
mac-address=00:23:8B:8A:6F:17
mac-address-blacklist=
[ipv4]
address1=116.255.147.45/27,116.255.147.33
dns=114.114.114.114;
dns-search=
method=manual
[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto
(2)、ubuntu 18.04 server版
2.1 ubuntu 18.4 server版网卡配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | root@htidc:~# vi /etc/netplan/50-cloud-init.yaml # This file is generated from information provided by # the datasource. Changes to it will not persist across an instance. # To disable cloud-init's network configuration capabilities, write a file # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following: # network: {config: disabled} network: ethernets: eno1: addresses: - 222.186.173.80/24 dhcp4: false gateway4: 222.186.173.254 nameservers: addresses: - 114.114.114.114 search: [] eno2: addresses: [] dhcp4: true optional: true version: 2 |
重启网卡命令
# netplan apply
2.2 ubuntu 18.04 server版多ip配置案例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | root@htidc:~# vi /etc/netplan/50-cloud-init.yaml # This file is generated from information provided by # the datasource. Changes to it will not persist across an instance. # To disable cloud-init's network configuration capabilities, write a file # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following: # network: {config: disabled} network: ethernets: eno1: addresses: - 222.186.173.80/24 - 222.186.169.222/24 dhcp4: false gateway4: 222.186.173.254 gateway4: 222.186.169.254 nameservers: addresses: - 114.114.114.114 search: [] eno2: addresses: [] dhcp4: true optional: true version: 2 |
重启网卡使得上面的配置生效
# netplan apply