I will need to do source routing and before going into more complicated setups I want to understand how this works by switching the generic routing (the one created magically by the networking setup) into a source routed one.
The goal is to create a specific routing table and set an ip rule
to route traffic from my IP through this routing table (which is, as far as I understand, what happens with the default
table). This is on a Debian 8 with one interface to which is assigned the IP 192.168.1.107
.
The problem is that this cloning does not work.
I first created an new entry in /etc/iproute2/rt_tables
200 NORMAL
I then dumped the current routing table - for a working networking
root@debian-testing:~# ip route show table all
default via 192.168.1.1 dev eth0
169.254.0.0/16 dev eth0 scope link metric 1000
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.107
broadcast 127.0.0.0 dev lo table local proto kernel scope link src 127.0.0.1
local 127.0.0.0/8 dev lo table local proto kernel scope host src 127.0.0.1
local 127.0.0.1 dev lo table local proto kernel scope host src 127.0.0.1
broadcast 127.255.255.255 dev lo table local proto kernel scope link src 127.0.0.1
broadcast 192.168.1.0 dev eth0 table local proto kernel scope link src 192.168.1.107
local 192.168.1.107 dev eth0 table local proto kernel scope host src 192.168.1.107
broadcast 192.168.1.255 dev eth0 table local proto kernel scope link src 192.168.1.107
I moved entries related to the real interface (192.168.1.107
) to table NORMAL
(what is below is the content of a file t.txt
which will be parsed in a moment)
root@debian-testing:~# cat t.txt
local 127.0.0.0/8 dev lo table local src 127.0.0.1
local 127.0.0.1 dev lo table local src 127.0.0.1
local 192.168.1.107 dev eth0 table NORMAL src 192.168.1.107
192.168.1.0/24 dev eth0 src 192.168.1.107 table NORMAL
broadcast 127.0.0.0 dev lo table local src 127.0.0.1
broadcast 127.255.255.255 dev lo table local src 127.0.0.1
broadcast 192.168.1.0 dev eth0 table NORMAL src 192.168.1.107
broadcast 192.168.1.255 dev eth0 table NORMAL src 192.168.1.107
default via 192.168.1.1 dev eth0 table NORMAL
I then flushed all existing routing entries, loaded the ones above and informed the system that packets from 192.168.1.107
should use the table NORMAL
root@debian-testing:~# ip route flush table all ; while read name; do echo "adding ${name}";ip route add ${name}; done < t.txt ; ip rule add from 192.168.0.107 table NORMAL
adding local 127.0.0.0/8 dev lo table local src 127.0.0.1
RTNETLINK answers: Invalid argument
adding local 127.0.0.1 dev lo table local src 127.0.0.1
adding local 192.168.1.107 dev eth0 table NORMAL src 192.168.1.107
adding 192.168.1.0/24 dev eth0 src 192.168.1.107 table NORMAL
adding broadcast 127.0.0.0 dev lo table local src 127.0.0.1
adding broadcast 127.255.255.255 dev lo table local src 127.0.0.1
adding broadcast 192.168.1.0 dev eth0 table NORMAL src 192.168.1.107
adding broadcast 192.168.1.255 dev eth0 table NORMAL src 192.168.1.107
adding default via 192.168.1.1 dev eth0 table NORMAL
Unfortunately now I cannot reach neither le local IP, nor an external host anymore, even though the routing table has been repopulated. The only ping which goes through is to 127.0.0.1
.
root@debian-testing:~# ping 8.8.8.8
connect: Network is unreachable
root@debian-testing:~# ping 192.168.1.107
connect: Network is unreachable
root@debian-testing:~# ip route
root@debian-testing:~# ip route show table all
default via 192.168.1.1 dev eth0 table NORMAL
broadcast 192.168.1.0 dev eth0 table NORMAL scope link src 192.168.1.107
192.168.1.0/24 dev eth0 table NORMAL scope link src 192.168.1.107
local 192.168.1.107 dev eth0 table NORMAL scope host src 192.168.1.107
broadcast 192.168.1.255 dev eth0 table NORMAL scope link src 192.168.1.107
broadcast 127.0.0.0 dev lo table local scope link src 127.0.0.1
local 127.0.0.1 dev lo table local scope host src 127.0.0.1
broadcast 127.255.255.255 dev lo table local scope link src 127.0.0.1
Where should I be looking for to fix this? Is my approach correct at all?
ping -c1 8.8.8.8
receive a reply?127.0.0.1
goes through.