ubuntu 18.04修改静态ip地址
1. 确认网卡名称
ip a #有ens开头的网卡,比如我的是ens160
2. DHCP的方式获取动态ip
vim /etc/netplan/00-installer-config.yaml network: ethernets: ens160: dhcp4: yes addresses: [] version: 2
3. 设置静态ip
vim /etc/netplan/00-installer-config.yaml network: ethernets: ens160: dhcp4: no addresses: [172.16.200.6/24] optional: true gateway4: 172.16.200.254 nameservers: addresses: [202.96.128.86,202.96.128.166] version: 2
4. 应用新的网卡配置信息
netplan apply
5. 测试网络连通性
ping www.baidu.com
PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data.
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=55 time=6.39 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=55 time=6.53 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=55 time=6.66 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=4 ttl=55 time=6.41 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=5 ttl=55 time=6.43 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=6 ttl=55 time=6.52 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=7 ttl=55 time=6.39 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=8 ttl=55 time=6.56 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=9 ttl=55 time=6.54 ms