Ubuntu 18 LTS netplan 网络配置

一、配置网络

1、通过netplan配置网络

#配置网络
nulige@ubuntu:/etc/netplan$ sudo apt install ifupdown

nulige@ubuntu:/etc/netplan$ cd /etc/netplan

nulige@ubuntu:/etc/netplan$ sudo vi 01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    ens33:
      addresses: [192.168.56.11/24]
      gateway4: 192.168.56.2
      nameservers:
        addresses: [192.168.56.2, 8.8.8.8]      
      dhcp4: no
      optional: no

nulige@ubuntu:/etc/netplan$ sudo netplan apply

nulige@ubuntu:/etc/netplan$ ip a
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:50:56:2b:1a:b2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.56.11/24 brd 192.168.56.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:fe2b:1ab2/64 scope link 
       valid_lft forever preferred_lft forever

2、配置一个网卡,两个IP地址

nulige@ubuntu:~$ cat /etc/network/interfaces
#sudo apt install ifupdown
auto lo
iface lo inet loopback

auto ens33
iface ens33 inet static
address 192.168.56.11
netmask 255.255.255.0
gateway 192.168.56.2

eg1:重启网络服务

sudo /etc/init.d/networking force-reload ==> 重新加载网路配置文件
sudo /etc/init.d/networking restart

eg2:重新启停以太网卡:

sudo ifconfig eth0 down
sudo ifconfig eth0 up

  

 

posted @ 2019-04-26 20:18  努力哥  阅读(8538)  评论(0编辑  收藏  举报