Ubuntu 18.04 uses elastic network card to configure multiple external network IP

After purchasing a server, there is only one public network IP by default. It is often encountered that a single external network IP cannot meet business needs. This article will introduce how a server can configure multiple IPs through a single network card or multiple network cards.

One, single network card configuration multiple IP

1、 lab environment##

Intranet IP Extranet IP
IP1 (default) 10.1.255.100 193.112.138.44
IP2 (Add) 10.1.255.101 106.53.17.193
IP3 (addition) 10.1.255.102 106.53.17.64

2、 Console assign IP

2.1 Assign intranet IP

2.2 Assign public IP

3、 Modify server network card configuration##

3.1 View network card information

3.2 Modify the network card configuration

ubuntu@VM-255-100-ubuntu:~$ sudo  vim /etc/netplan/50-cloud-init.yaml 
ubuntu@VM-255-100-ubuntu:~$ cat /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network:{config: disabled}
network:
 version:2
 ethernets:
  eth0:
   addresses:-10.1.255.100/24-10.1.255.101/24-10.1.255.102/24
   ### The main modification is the addresses part.
   match:
    macaddress:52:54:00:fa:d3:fc
   nameservers:
    addresses:-183.60.83.19-183.60.82.98
   routes:-   to:0.0.0.0/0
    via:10.1.255.1set-name: eth0
ubuntu@VM-255-100-ubuntu:~$ 
ubuntu@VM-255-100-ubuntu:~$ sudo  netplan apply
ubuntu@VM-255-100-ubuntu:~$ 

3.3 Check the network card information again

4、 Test Results##

All three external network IPs can be pinged and ssh can be used to log in. The single network card configuration has been completed.

Two, multiple network card configuration multiple IP

The above one network card can be configured with multiple IPs, why use multiple network cards?

For example, one person can put 5 cows, then 2 people can put 10 cows, and three people can put 15 cows............

1、 lab environment##

Main network card Intranet IP Extranet IP
IP1 (default) 10.1.255.100 193.112.138.44
IP2 (Add) 10.1.255.101 106.53.17.193
IP3 (addition) 10.1.255.102 106.53.17.64
Auxiliary Network Card Intranet IP External IP
IP1 10.1.255.110 123.207.94.225
IP2 10.1.255.111 134.175.127.250

2、 Create a new elastic network card (auxiliary network card)

PS: The console prompts friendly here, reminding us to modify the IP and routing in the server, otherwise communication will not be possible, click OK to start creating.

3、 Auxiliary network card binding external network IP

4、 Modify server configuration##

4.1 View network card information

Here the auxiliary network card (eth1) device has been displayed, but there is no IP information to see, so it cannot communicate.

4.2 Modify the network card configuration

ubuntu@VM-255-100-ubuntu:~$ sudo vim /etc/netplan/50-cloud-init.yaml 
ubuntu@VM-255-100-ubuntu:~$ cat /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network:{config: disabled}
network:
 version:2
 ethernets:
  eth0:
   addresses:-10.1.255.100/24-10.1.255.101/24-10.1.255.102/24
   match:
    macaddress:52:54:00:fa:d3:fc
   nameservers:
    addresses:-183.60.83.19-183.60.82.98
   routes:-   to:0.0.0.0/0
    via:10.1.255.1set-name: eth0

### The auxiliary network card is configured as eth1, which is a newly added configuration.
  eth1:
   addresses:-10.1.255.110/24-10.1.255.111/24
   match:
    macaddress:20:90:6F:4D:50:47
### The MAC address of the network card. This parameter is not required. To view the MAC address, please refer to the official website document(https://cloud.tencent.com/document/product/576/18533)
   nameservers:
    addresses:-183.60.83.19-183.60.82.98
   routes:-   to:0.0.0.0/0
    via:10.1.255.1set-name: eth1
ubuntu@VM-255-100-ubuntu:~$ 
ubuntu@VM-255-100-ubuntu:~$ sudo  netplan apply
ubuntu@VM-255-100-ubuntu:~$ 

4.3 Check the network card information again

4.4 Turn off rp_filter verification

ubuntu@VM-255-100-ubuntu:~$ sudo vim /etc/sysctl.conf 
ubuntu@VM-255-100-ubuntu:~$ 
ubuntu@VM-255-100-ubuntu:~$ tail -4/etc/sysctl.conf 
net.ipv4.conf.default.rp_filter =0
net.ipv4.conf.all.rp_filter =0
net.ipv4.conf.eth0.rp_filter =0
net.ipv4.conf.eth1.rp_filter =0
### Add these four lines of configuration at the end of this file, comment net.ipv4.conf.default.rp_filter =1。

ubuntu@VM-255-100-ubuntu:~$ 
ubuntu@VM-255-100-ubuntu:~$ sudo sysctl -p  ###Take effect after executing this command
kernel.sysrq =1
net.ipv6.conf.all.disable_ipv6 =1
net.ipv6.conf.default.disable_ipv6 =1
kernel.printk =5
net.ipv4.conf.default.rp_filter =0
net.ipv4.conf.all.rp_filter =0
net.ipv4.conf.eth0.rp_filter =0
net.ipv4.conf.eth1.rp_filter =0

5、 Test Results##

The two external IPs of the auxiliary network card can also be connected by ping and ssh, and the configuration of multiple network cards has been completed.

Three, supplement#

1、 The server must be a private network, and the basic network cannot use an elastic network card.

2、 Depending on the CPU and memory configuration, the number of flexible network cards that can be bound to [Cloud Server] (https://cloud.tencent.com/product/cvm?from=10680) and the number of internal network IPs bound to a single network card are quite different. Please refer to Official Website Instructions.

3、 Please refer to Official Website Document for related operations of the elastic network card

Four, other system configuration documents#

CentOS

Centos7 server main network card binding multi-ip practice demonstration

Centos7 server adds auxiliary network card to bind multi-ip practice demonstration

Windows

Windows server main network card binding multi-ip practice demonstration

Windows server add auxiliary network card and bind multi-ip practice demonstration

Recommended Posts

Ubuntu 18.04 uses elastic network card to configure multiple external network IP
Ubuntu16.04 configure your own network card information
Ubuntu 18.04 network card configuration
ubuntu 14.04 configure 3-wire 3IP
How to configure a fixed IP based on Ubuntu 18.04
Tencent cloud centos 8.0 single network card configuration multiple IP
Centos configure multiple virtual IP
ubuntu modify and configure ip address
Ubuntu uses Docker to install Gitlab
Ubuntu16.04 uses composer to install laravel framework
Ubuntu uses cron to implement scheduled tasks
How to configure Redis cluster on Ubuntu 14.04
How to set static IP in ubuntu14.04
How to configure Redis replication on Ubuntu 16.04