Documentation
Linux Advanced Routing & TC: http://lartc.org/howto/index.html
Basic commands
I guess ifconfig is deprecated now…
Help:
ip a help
( a
=address l
=link r
=route )
Show:
ip a show eth0
ip l show eth0
ip r get 8.8.8.8
( use
ip -4
or -6
for ipv4/6 )
Change:
ip l set dev eth0 up
ip a add 192.168.1.2/24 dev eth0
.
Two Default Gateways
Useful to setup for hosts on multiple subnets/networks.
Howto’s:
- https://www.thomas-krenn.com/en/wiki/Two_Default_Gateways_on_One_System
- http://www.rjsystems.nl/en/2100-adv-routing.php
- https://kindlund.wordpress.com/2007/11/19/configuring-multiple-default-routes-in-linux/
- http://www.dfwavc.com/linux_multi_nic-multi_gateway
Instructions
Add table:
echo -e "10\trt2" >> /etc/iproute2/rt_tables
Add route/rule:
ip route add 1.2.3.0/20 dev eth1 src 1.2.3.172 table rt2 ip route add default via 1.2.3.1 dev eth1 table rt2 ip rule add from 1.2.3.172/32 table rt2 ip rule add to 1.2.3.172/32 table rt2 ip rule add from 1.2.3.173/32 table rt2 ip rule add to 1.2.3.173/32 table rt2 ip route flush cache ip route list table rt2 ip route show ip rule show
Testing:
ping -I 1.2.3.172 8.8.8.8
Making it permanent
debian:
/etc/interfaces
/etc/network/interfaces.d/eth1
post-up ip route add 1.2.3.0/20 dev eth1 src 1.2.3.174 table rt2
post-up ip route add default via 1.2.3.1 dev eth1 table rt2
post-up ip rule add from 1.2.3.174/32 table rt2
post-up ip rule add to 1.2.3.174/32 table rt2
/etc/network/interfaces.d/eth1:0
post-up ip rule add from 1.2.3.176/32 table rt2
post-up ip rule add to 1.2.3.176/32 table rt2
redhat:
echo "1.2.3.0/20 dev eth1 src 1.2.3.172 table rt2" >> /etc/sysconfig/network-scripts/route-eth1
echo "default via 1.2.3.1 dev eth1 table rt2" >> /etc/sysconfig/network-scripts/route-eth1
echo "from 1.2.3.172/32 table rt2" >> /etc/sysconfig/network-scripts/rule-eth1
echo "to 1.2.3.172/32 table rt2" >> /etc/sysconfig/network-scripts/rule-eth1
echo "from 1.2.3.173/32 table rt2" >> /etc/sysconfig/network-scripts/rule-eth1
echo "to 1.2.3.173/32 table rt2" >> /etc/sysconfig/network-scripts/rule-eth