ubuntu20.04禁用dhcp应用动态ip注意事项
假如要把ip地址设为 192.168.1.38 子网掩码24位即255.255.255.0
首先确认网卡名称 应用ifconfig命令:
`eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.39 netmask 255.255.255.0 broadcast 192.168.1.255`
网卡名称 eno1 目前的ip地址是192.168.1.39,子网掩码24位
确认网关地址:应用 route -n 命令
`Destination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 192.168.1.1 0.0.0.0 UG 100 0 0 eno1`
默认网关 192.168.1.1
最初编辑 sudo vim /etc/netplan/01-network-manager-all.yaml 填入:
`network: version: 2 renderer: NetworkManager ethernets: eno1: # 网卡名称 dhcp4: no # 敞开dhcp dhcp6: no addresses: [192.168.1.38/24] # 动态ip gateway4: 192.168.1.1 # 网关 nameservers: addresses: [8.8.8.8, 114.114.114.114]`# dns
运行 sudo netplan apply
使配置失效
在网络连接里,能够找到最新配置的连贯
再运行 ifconfig 发现ip曾经改了
`inet 192.168.1.38 netmask 255.255.255.0 broadcast 192.168.1.255
`