hopeless-dream

导航

Ubuntu配置静态IP

Ubuntu18.04配置静态IP

18.04和之前的版本配置静态IP上有很大差异,使用yaml文件进行配置。

查看本机IP

root@root:/etc/netplan# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:02:03:2b brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.128/24 brd 10.0.0.255 scope global dynamic ens33
       valid_lft 1695sec preferred_lft 1695sec
    inet6 fe80::20c:29ff:fe02:32b/64 scope link 
       valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:69:ec:37:e6 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever

除了docker0桥只有一块动态的网卡ens33

查看ens33动态IP的配置文件

root@root:/etc/netplan# cat 00-installer-config.yaml 
# This is the network config written by 'subiquity'
network:
  ethernets:
    ens33:
      dhcp4: true
  version: 2

编辑网络配置文件(在/etc/netplan)

root@root:/etc/netplan# vim 00-installer-config.yaml

network:
  version: 2
  ethernets:
    ens33: #配置的网卡名称,使用ifconfig -a查看得到
      dhcp4: no #dhcp4关闭
      addresses: [10.0.0.220/24] #设置本机IP及掩码
      gateway4: 10.0.0.226 #设置网关
      nameservers:
        addresses: [10.0.0.226] #设置DNS

使用netplan使配置生效

root@root:/etc/netplan# netplan apply 

 

posted on 2020-05-03 21:50  hopeless-dream  阅读(1057)  评论(0编辑  收藏  举报