码迷,mamicode.com
首页 > 系统相关 > 详细

Ubuntu 18.04 设置静态 ip 的方法

时间:2020-03-14 22:21:45      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:use   sed   ESS   etc   queue   broadcast   static   down   还原   

 

查看网卡名

$ ifconfig
enp6s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.1.20  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::ca5b:76ff:fe5d:8241  prefixlen 64  scopeid 0x20<link>
        ether c8:5b:76:5d:82:41  txqueuelen 1000  (Ethernet)
        RX packets 1139  bytes 159452 (159.4 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1059  bytes 96481 (96.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0...

 

方法1(需要重启才能生效)

打开,

$ sudo vim /etc/network/interfaces

如下修改,重启生效(使用 $ sudo service networking restart 无效),

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

#################################################### Add by User Start
uto enp6s0
iface enp6s0 inet static
address 192.168.1.20
netmask 255.255.255.0
#getway 192.168.1.1     # 一般不用设置
#################################################### Add by User End

 

方法2(不需要重启)推荐

打开,

$ sudo vim /etc/netplan/01-network-manager-all.yaml    # 一般仅有一个 .yaml 文件

原始内容为,

# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager

修改为固定 ip 地址 ,

# Let NetworkManager manage all devices on this system
#network:
#  version: 2
#  renderer: NetworkManager
#  ethernets:
#      enp6s0:
#          dhcp4: yes 

network:
  version: 2
  ethernets:
      enp6s0:
          dhcp4: no
          addresses: [192.168.1.22/24]
          optional: true
          gateway4: 192.168.1.1
          nameservers:
              addresses: [192.168.1.1]

执行,

$ sudo netplan apply 

 如果要还原更改为 DHCP,修改上述文件为,

# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  ethernets:
      enp6s0:
          dhcp4: yes 

#network:
#  version: 2
#  ethernets:
#      enp6s0:
#          dhcp4: no
#          addresses: [192.168.1.22/24]
#          optional: true
#          gateway4: 192.168.1.1
#          nameservers:
#              addresses: [192.168.1.1]

再次执行,

$ sudo netplan apply

 

完。

 

Ubuntu 18.04 设置静态 ip 的方法

标签:use   sed   ESS   etc   queue   broadcast   static   down   还原   

原文地址:https://www.cnblogs.com/gaowengang/p/12494267.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!