Knowledge Base Ever

A CentOS server with a dual NIC installed in the LAN and connected to the dual intranet segment can realize simultaneous access of dual public IP through router port forwarding.

2019-11-11 17:09:37

label: CentOS, dual network interfaces, ip command, Dual NIC, dual NIC routing, dual public IP

Scenario: A server is in the LAN, and provides services through the port mapping of the router. The server is equipped with dual network cards, which belong to different intranet segments. Each network segment has a public IP address mapped to the server.

Symptom: The public IP address corresponding to the default NIC in the two NICs of the server can access the server normally, and the other IP cannot be accessed.

Solution: You need to configure the two public IP addresses to access the server. Assume that the two network segments are: 192.168.0 and 192.168.1, and the IP addresses of the server on the two network segments are: and, and the network card names are: enp2s0 and enp3s0. The routing configuration is as follows:
echo "101 Net1" >> /etc/iproute2/rt_tables
echo "102 Net2" >> /etc/iproute2/rt_tables

ip route add default via dev enp2s0 table Net1
ip route add default via dev enp3s0 table Net2

ip rule add from table Net1
ip rule add from table Net2


CentOS7 CentOS PHP Linux Python Python3 MySQL MariaDB YUM JavaScript HTML mysql_native_password PHP7 CSS Redis MySQL8 caching_sha2_password Apache2.4 Elasticsearch libpython3.7m.so.1.0 PHPStorm ss5-3.8.9 VIM CURLOPT_POSTFIELDS NodeJs show Bluetooth Failed to build these modules: _ctypes Minimal ISO substr Wi-Fi date sub INTERVAL PECL SQL Date Funcitons Tag Cloud CodeIgniter font-size root apache httpd dual network interfaces Laravel ss5 vertical-align CURLFille horiz-align node.js ShadowsocksR BarManager exec mb_substr PyCharm SUBDATE WebStorm date add IntelliJIDEA PEAR SOCKS5 Proxy Server Chrome find remi Tag Apache du jQuery PHP5.5 src V2Ray cURL hide nginx Shadowsocks-Python availability eth0 MariaDB10.4 PostgreSQL sub folder Web Server date Install MongoDB pdo_sqlsrv SOCKS5 File Upload mssql-tools register_shutdown_function Symfony Zend Framework ADDDATE DevExpress JetBrain php-fpm sqlsrv unixODBC-devel height network interface Shadowsocks-Libev Aura error_get_last Port 80 string Web Development data INDENTIFIED BY password policy requirements SOCKS Fedora Media Writer msodbcsql Redis5 SVN absolute Deepin jemalloc SQLAlchemy toggle convert FuelPHP mysqlclient Shadowsocks at-symbol Error Control Operator margin PHPUnit Framework ss5.passwd vps daemon process IIS password SOCKET center Fatal Errors MongoDB4 sudoers WiFi .htaccess DATE_SUB Phalcon SQL Server 2017 TestCase Compiling PHP frequency conflict set_error_handler apr Elasticsearch7.3 PHPUnit ss5.conf Vincent Garreau daemon HTTP particles.js Slim Failed to build these modules: _uuid MongoDB Sudo width DATE_ADD ip command pg_bha.conf SQL Server Tcp BBR Compiling Apache Frameworks MySQL-python scrollbar