Ubuntu virtual machine multi network card configuration

  • 2020-05-30 21:41:45
  • OfStack

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

#auto ens33
iface ens33 inet static

#auto ens34
iface ens34 inet static

#auto ens35
iface ens35 inet dhcp

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 gw
route add -net gw
route add -net gw
route del default gw 
route add default gw dev ens35
chmod 111 /etc/init.d/configNetwork
sed -i '/exit 0/i\bash /etc/init.d/configNetwork' /etc/rc.local

The above configuration is implemented:
1) when the system starts, run the customized script (Ubuntu16.04 starts the execution script slightly different)
2) when the system is started, the script executes the network card action
3) the system realizes the communication of multiple network segments, and the default gateway is started and modified each time

Related articles: