- Newest
- Most votes
- Most comments
Centos Configuration:
-
Console creates ENI, assigns multiple Private IPs and EIPs
-
Using two network cards as an example
- ETH1:
- EIP: 43.192.X.X, Private IP: 172.31.20.163
- EIP: 161.189.X.X, Private: 172.31.26.128
- ETH0:
- EIP1: 69.231.X.X, Private IP: 172.31.24.205
- EIP2: 69.234.X.X, Private IP: 172.31.23.41
- ETH1:
-
Create the following files in
/etc/sysconfig/network-scripts
, each network card and each IP requires a corresponding file:ifcfg-eth0 can omit IP and MASK, other configuration files need to write the corresponding Private IP and NET MASK (consistent with subnet configuration)
ifcfg-eth0:
BOOTPROTO=dhcp DEVICE=eth0 HWADDR=06:aa:d7:88:4d:b2 ##optional ONBOOT=yes STARTMODE=auto TYPE=Ethernet USERCTL=no
ifcfg-eth0:1
# BOOTPROTO=dhcp DEVICE=eth0:1 ONBOOT=yes IPADDR=172.31.23.41 # Second IP of ETH0 NETMASK=255.255.240.0 STARTMODE=auto TYPE=Ethernet USERCTL=no
ifcfg-eth1
BOOTPROTO=dhcp DEVICE=eth1 ONBOOT=yes IPADDR=172.31.20.163 # First IP of ETH1 NETMASK=255.255.240.0 STARTMODE=auto TYPE=Ethernet USERCTL=no
ifcfg-eth1:1
BOOTPROTO=dhcp DEVICE=eth1:1 ONBOOT=yes IPADDR=172.31.26.128 # Second IP of ETH1 NETMASK=255.255.240.0 STARTMODE=auto TYPE=Ethernet USERCTL=no
-
Update the /etc/rc.local file, adding the following entries to this file to ensure the routing table is automatically updated after the server restarts
## Different network cards use different policy routing ip route add default via 172.31.16.1 dev eth0 table 1 # ETH0 uses table 1 ip rule add from 172.31.24.205 lookup 1 # Set source return path ip rule add from 172.31.23.41 lookup 1 ip route add default via 172.31.16.1 dev eth1 table 2 # ETH1 uses table 2 ip rule add from 172.31.20.163 lookup 2 ip rule add from 172.31.26.128 lookup 2
After adding, execute
chmod +x /etc/rc.d/rc.local
Restart the system to check if all IPs can communicate properly.
Note: If communication still fails after restarting, configure the rc-local service.
-
Edit
/usr/lib/systemd/system/rc-local.service
Add dependencies:
In the
[Unit]
section, ensure the following two lines are included:Requires=network-online.target After=network-online.target
Save and exit
-
Enable rc-local.service
sudo systemctl enable rc-local
-
Start the service
sudo systemctl start rc-local
sudo systemctl status rc-local
Restart again, and you should be able to ping all IPs.
The configuration for Amazon Linux is simpler since it comes pre-installed with amazon-ec2-net-utils, which automatically recognizes network card information and has fewer configuration items; you can refer to the above steps to update any missing parts accordingly.
Relevant content
- asked 2 years ago
- asked a month ago
- AWS OFFICIALUpdated 2 months ago
- AWS OFFICIALUpdated 4 months ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated 4 months ago