routing is all about – TCP/IP and the route traffic/packages must/need/can take to the target (webserver, mailserver, youtube.com) and back.
alias = “virtual network card” = you can have multiple ip-addresses per phyisical network card.
under linux the naming is: eth0:0, eth0:1, eth0:2…
those are basically “virtual network cards” each having their own unique ip-address (may not conflict/collide, not possible to have same ip assigned to two aliases)
show routing table
route; # show the current routing table # alternatively netstat -nr Kernel IP Routentabelle Ziel Router Genmask Flags MSS Fenster irtt Iface 0.0.0.0 172.20.0.1 0.0.0.0 UG 0 0 0 eth0 172.20.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 ip route show default via 172.20.0.1 dev eth0 proto dhcp 172.20.0.0/16 dev eth0 proto kernel scope link src 172.20.0.25
the UG means default gateway – all packages it does not know where to send to go to the default gateway. (it tries all the other routes first)
the 0.0.0.0 represents the current local network the machine is directly attached to.
add new route
ifconfig eth0:0 192.168.1.123 up; # create new virtual interface route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 dev eth0; root@Debian8:~# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default 172.20.0.1 0.0.0.0 UG 0 0 0 eth0 172.20.0.0 * 255.255.0.0 U 0 0 0 eth0 192.168.1.0 192.168.1.1 255.255.255.0 UG 0 0 0 eth0 192.168.1.0 * 255.255.255.0 U 0 0 0 eth0 root@Debian8:~# ip route show default via 172.20.0.1 dev eth0 172.20.0.0/16 dev eth0 proto kernel scope link src 172.20.0.12 192.168.1.0/24 via 192.168.1.1 dev eth0 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.123
delete all default gateways / reset all connections
service network restart; # centos/suse - reset network service networking restart; # debian/ubuntu - reset network
example routing ride:
ifconfig; # show interfaces eth0 Link encap:Ethernet Hardware Adresse 00:15:5D:00:07:09 inet Adresse:172.20.0.25 Bcast:172.20.255.255 Maske:255.255.0.0 ... lo Link encap:Lokale Schleife inet Adresse:127.0.0.1 Maske:255.0.0.0 ... ifconfig eth0:0 192.168.2.40; # create new "virtual network card" = alias ip addr add 192.168.2.40/24 dev eth0 brd + label eth0:0; # exactly the same but with alternative command ip ifconfig eth0 Link encap:Ethernet Hardware Adresse 00:15:5D:00:07:09 inet Adresse:172.20.0.25 Bcast:172.20.255.255 Maske:255.255.0.0 ... eth0:0 Link encap:Ethernet Hardware Adresse 00:15:5D:00:07:09 = new virtual device added inet Adresse:192.168.2.40 Bcast:192.168.2.255 Maske:255.255.255.0 ... lo Link encap:Lokale Schleife inet Adresse:127.0.0.1 Maske:255.0.0.0 ... ifconfig eth0:1 192.168.2.40; # create new "virtual network card" = alias, with same ip, is not allowed SIOCSIFADDR: Die Datei existiert bereits SIOCSIFFLAGS: Die angeforderte Adresse kann nicht zugewiesen werden route add -net 192.168.1.0 netmask 255.255.255.0 dev eth0; # tell computer that it can reach 1.XXX subnet via device eth0 # you do not have to have an ip (alias) asigned to your local network card in the segment 192.168.1.XXX to reach that network # but you will have to have a route ;) route Kernel IP Routentabelle Ziel Router Genmask Flags Metric Ref Use Iface default 172.20.0.1 0.0.0.0 UG 0 0 0 eth0 172.20.0.0 * 255.255.0.0 U 0 0 0 eth0 192.168.1.0 * 255.255.255.0 U 0 0 0 eth0 = was newly added to table route add -net 192.168.2.0 netmask 255.255.255.0 dev eth0:0; # tell computer that it can reach 2.XXX subnet via device eth0:0 route Kernel IP Routentabelle Ziel Router Genmask Flags Metric Ref Use Iface default 172.20.0.1 0.0.0.0 UG 0 0 0 eth0 172.20.0.0 * 255.255.0.0 U 0 0 0 eth0 192.168.1.0 * 255.255.255.0 U 0 0 0 eth0 192.168.2.0 * 255.255.255.0 U 0 0 0 eth0 192.168.2.0 * 255.255.255.0 U 0 0 0 eth0 = was newly added to table route add -host 112.22.3.4 dev ppp0; # tell computer that can reach host with ip 112.22.3.4 via ppp0 (modem) # will give an error if device does not exist route add -host 112.22.3.4 dev eth0; # tell computer that can reach host with ip 112.22.3.4 via eth0 route Kernel IP Routentabelle Ziel Router Genmask Flags Metric Ref Use Iface default 172.20.0.1 0.0.0.0 UG 0 0 0 eth0 112.22.3.4 * 255.255.255.255 UH 0 0 0 eth0 = was newly added to table 172.20.0.0 * 255.255.0.0 U 0 0 0 eth0 192.168.1.0 * 255.255.255.0 U 0 0 0 eth0 192.168.2.0 * 255.255.255.0 U 0 0 0 eth0 192.168.2.0 * 255.255.255.0 U 0 0 0 eth0 route add default gw 192.168.1.1; # add new default gateway (how to reach all other subnets - not explicitly named in the local routing table) route Kernel IP Routentabelle Ziel Router Genmask Flags Metric Ref Use Iface default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0 = was newly added to table default 172.20.0.1 0.0.0.0 UG 0 0 0 eth0 112.22.3.4 * 255.255.255.255 UH 0 0 0 eth0 172.20.0.0 * 255.255.0.0 U 0 0 0 eth0 192.168.1.0 * 255.255.255.0 U 0 0 0 eth0 192.168.2.0 * 255.255.255.0 U 0 0 0 eth0 192.168.2.0 * 255.255.255.0 U 0 0 0 eth0 route del default; # delete last added default gateway route Kernel IP Routentabelle Ziel Router Genmask Flags Metric Ref Use Iface default 172.20.0.1 0.0.0.0 UG 0 0 0 eth0 112.22.3.4 * 255.255.255.255 UH 0 0 0 eth0 172.20.0.0 * 255.255.0.0 U 0 0 0 eth0 192.168.1.0 * 255.255.255.0 U 0 0 0 eth0 192.168.2.0 * 255.255.255.0 U 0 0 0 eth0 192.168.2.0 * 255.255.255.0 U 0 0 0 eth0 route del -net 192.168.2.0 netmask 255.255.255.0; # delete specific route (one has two routes of that kind) route Kernel IP Routentabelle Ziel Router Genmask Flags Metric Ref Use Iface default 172.20.0.1 0.0.0.0 UG 0 0 0 eth0 112.22.3.4 * 255.255.255.255 UH 0 0 0 eth0 172.20.0.0 * 255.255.0.0 U 0 0 0 eth0 192.168.1.0 * 255.255.255.0 U 0 0 0 eth0 192.168.2.0 * 255.255.255.0 U 0 0 0 eth0 route del -net 192.168.2.0 netmask 255.255.255.0; # delete specific route (one has one route of that kind) route Kernel IP Routentabelle Ziel Router Genmask Flags Metric Ref Use Iface default 172.20.0.1 0.0.0.0 UG 0 0 0 eth0 112.22.3.4 * 255.255.255.255 UH 0 0 0 eth0 172.20.0.0 * 255.255.0.0 U 0 0 0 eth0 192.168.1.0 * 255.255.255.0 U 0 0 0 eth0 route del -net 192.168.2.0 netmask 255.255.255.0; # delete specific route (one has deleted all routes of that kind) SIOCDELRT: Kein passender Prozess gefunden = hence the error message ifconfig eth0:0 down; # remove "virtual network card" = alias
happy routes! get your traffic through 😉 may the source and the routing-table be with you!
manpages:
liked this article?
- only together we can create a truly free world
- plz support dwaves to keep it up & running!
- (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
- really really hate advertisement
- contribute: whenever a solution was found, blog about it for others to find!
- talk about, recommend & link to this blog and articles
- thanks to all who contribute!