Ubuntu 18 LTS netplan 网络配置

Posted nulige

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ubuntu 18 LTS netplan 网络配置相关的知识,希望对你有一定的参考价值。

一、配置网络

1、通过netplan配置网络

#配置网络
[email protected]:/etc/netplan$ sudo apt install ifupdown

[email protected]:/etc/netplan$ cd /etc/netplan

[email protected]:/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

[email protected]:/etc/netplan$ sudo netplan apply

[email protected]:/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地址

[email protected]:~$ 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

  

 

以上是关于Ubuntu 18 LTS netplan 网络配置的主要内容,如果未能解决你的问题,请参考以下文章

ubuntu18.04LTS设置静态IP

Ubuntu 18.04 LTS IP 地址设置

ubuntu18.04netplan命令没有

Ubuntu18.04LTS配置静态ip

Ubuntu18.04 IP配置问题

ubuntu20netplan命令找不到