Content: how to make the computer respond on the Internet to all its IP addresses on all its interfaces, each of which has a default gateway. It applies to both servers and desktops.
Summary:
Configure the iproute2 utility using the config (all of a sudden, it has a config!) – give names to three routing tables
Set up routes in three routing tables – more precisely, set default routes
Specify the rules by which traffic will be distributed across three route tables
In our example, we will have 2 interfaces. Which are called ens33 and ens192.
Gateway 1 ip address – 192.168.1.1
Gateway 2 ipaddress – 192.168.2.1,
server interface ens33 ip – 192.168.1.10
server interface ens192 ip – 192.168.2.10
- Create routing tables.
# echo 100 ens33-route >>/etc/iproute2/rt_tables # echo 101 ens192-route >>/etc/iproute2/rt_tables
2. We set default gateways for each interface
ip route add default via 192.168.2.1 dev ens192 table ens192-route ip route add default via 192.168.1.1 dev ens33 table ens33-route
3. Set ip rules
ip rule add from 192.168.2.10 lookup ens192-route ip rule add from 192.168.1.10 lookup ens33-route
Now our server responds to the interface from which the request comes. Even without rebooting the system
If you want this to work after a system reboot, do the following:
Open /etc/network/interfaces . Then config:
iface ens192 inet static address 192.168.2.10 netmask 255.255.255.0 post-up ip route add default via 192.168.2.1 dev ens192 table ens192-route post-up ip rule add from 192.168.2.10 lookup ens192-route iface ens33 inet static address 192.168.1.10 netmask 255.255.255.0 post-up ip route add default via 192.168.1.1 dev ens33 table ens33-route post-up ip rule add from 192.168.1.10 lookup ens33-route
Save and reboot.
Similar Posts:
- howto use netplan in ubuntu 20.04 with 2 lan interfaces + policy based routing
- HOW TO BLOCK AN IP ADDRESS ON A LINUX SERVER
- How to change static ip address on Ubuntu server 18.04
- CSF CLI (Command Line Interface) Cheat Sheet
- How to connect L2TP + Ipsec client to Mikrotik Router