This article for you to share Ubuntu virtual machine multi-network card configuration, for your reference, the specific content is as follows
1. Scene description
System platform: Ubuntu 16.04 Server: VMWare workstation virtual machine 12c Solve the problem: add 4 network CARDS (4 network segments and 4 gateways), and the 4th network card nat can surf the Internet, but the default route has problems
2, network card configuration content
root@Ocommon:~# cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
#auto ens32
iface ens32 inet static
address 1.1.1.2
netmask 255.255.255.0
gateway 1.1.1.1
#auto ens33
iface ens33 inet static
address 2.2.2.2
netmask 255.255.255.0
gateway 2.2.2.1
#auto ens34
iface ens34 inet static
address 3.3.3.2
netmask 255.255.255.0
gateway 3.3.3.1
#auto ens35
iface ens35 inet dhcp
Note: However, when “#auto ens3*” is added, there will be an error when it is started. Therefore, all #auto ens3* is removed. However, when it is started, the network card cannot be displayed normally.
3, Ubuntu virtual machine multi-network card configuration supplementary content
According to the above configuration Ubuntu16.04 virtual machine network card configuration, need to solve the network card startup, multi-network routing problems
cat >/etc/init.d/configNetwork<<EOF11
ifup ens32
ifup ens33
ifup ens34
ifup ens35
route add -net 1.1.1.0 gw 1.1.1.1
route add -net 2.2.2.0 gw 2.2.2.1
route add -net 3.3.3.0 gw 3.3.3.1
route del default gw 1.1.1.1
route add default gw 192.168.137.2 dev ens35
EOF11
chmod 111 /etc/init.d/configNetwork
sed -i '/exit 0/i\bash /etc/init.d/configNetwork' /etc/rc.local
The above configuration is implemented:
- when the system starts, run the customized script (Ubuntu16.04 starts the execution script slightly different)
- when the system is started, the script executes the network card action
- the system realizes the communication of multiple network segments, and the default gateway is started and modified each time