Centos (Linux) adding multiple IP addresses and adding NIC Routing
Step-1:-
NIC Interfaces config are as follow :
root#cd /etc/sysconfig/network-scripts
ETH0 : (ifcfg-ens160)
TYPE="Ethernet"
NAME="ens160"
UUID="21a11fc4-899c-4d3c-bf55-82cb2b5b64ab"
ONBOOT="yes"
HWADDR="90:0C:29:fg:2B:44"
IPADDR=192.168.100.211
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
ETH1 : (ifcfg-ens192)
TYPE="Ethernet"
IPADDR=103.58.120.120
NETMASK=255.255.255.240
GATEWAY=103.58.120.113
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
DNS1=103.58.200.2
DNS2=8.8.8.8
NAME="ens192"
ONBOOT="yes"
HWADDR="00:0c:29:ed:2b:11"
PEERDNS="yes"
PEERROUTES="yes"
Step-2:-
Add default External Geway address (Optional).
[root@localhost sysconfig]# cat /etc/sysconfig/network
GATEWAY=103.58.120.113
Step-3:-
Create Shell scripts adding both IP address gateway for simultaneous access.
root#vi /root/network.sh
#!/bin/sh
ip rule add from 103.58.120.112/28 pref 200 lookup 201
ip route add default via 103.58.120.113 dev ens192 table 201
ip rule add from 192.168.100.0/24 pref 200 lookup 202
ip route add default via 192.168.100.1 dev ens160 table 202
ip route flush cache
Reference Note:-
103.58.120.112/28 - Subnet
103.58.120.113 - Gateway
192.168.100.0/24 - Subnet
192.168.100.1 - Gateway
Step-4:-
Provide execute permission shell scripts.
root#chmod 755 /root/network.sh
root#chmod +x /root/network.sh
Step-5:-
Add shell script file path into init.d network file for auto adds the default gateway. if any node restart.
root#vi /etc/init.d/network
#! /bin/bash
#
# network Bring up/down networking
#
# chkconfig: 2345 10 90
# description: Activates/Deactivates all network interfaces configured to \
# start at boot time.
#
### BEGIN INIT INFO
# Provides: $network
# Should-Start: iptables ip6tables NetworkManager-wait-online NetworkManager
# Short-Description: Bring up/down networking
# Description: Bring up/down networking
### END INIT INFO
./root/network.sh
Step-6:-
Perform the restart command.
root#reboot
After successful Reboot the Linux system. It will accessible both IP address segments.
Reference other sites - https://serverfault.com/questions/567249/centos-multiple-nics-routing-issue
No comments:
Post a Comment