ubuntu20.04 设置静态ip

ubuntu20.04禁用dhcp使用静态ip注意事项ubuntu

假设要把ip地址设为 192.168.1.38 子网掩码24位即255.255.255.0
首先确认网卡名称 使用ifconfig命令:vim

`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 命令app

`Destination     Gateway         Genmask        Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    100    0        0 eno1`

默认网关 192.168.1.1spa

最后编辑 sudo vim /etc/netplan/01-network-manager-all.yaml 填入:code

`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
使配置生效
在网络链接里,能够找到最新配置的链接
Screenshot from 2020-07-29 21-29-53.pngserver

再运行 ifconfig 发现ip已经改了dns

`inet 192.168.1.38  netmask 255.255.255.0  broadcast 192.168.1.255

`ip

相关文章
相关标签/搜索