1、配置網絡ubuntu
一、經過netplan配置網絡bash
#配置網絡 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
二、配置一個網卡,兩個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:重啓網絡服務app
sudo /etc/init.d/networking force-reload ==> 從新加載網路配置文件 sudo /etc/init.d/networking restart
eg2:從新啓停以太網卡:oop
sudo ifconfig eth0 down sudo ifconfig eth0 up