How to change loopback network mask or redirect subnet to another interface [closed]

I have the following problem.
First of all. Here are my interfaces.

# ip addr
ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever

2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
    inet 10.10.1.15/24 brd 10.10.1.255 scope global eth1
    inet6 fe80::a00:27ff:fe28:b0c4/64 scope link
       valid_lft forever preferred_lft forever

As you can see the loopback interface serves following network 127.0.0.1/8, the network mask is 255.0.0.0.

My problem is that I need to route all traffic for example for the network 127.22.0.0/16 to the interface eth1.

I have following routes now

default via 10.10.1.2 dev eth1
default via 10.10.1.2 dev eth1  metric 203
10.10.1.0/24 dev eth1  scope link
10.10.1.0/24 dev eth1  proto kernel  scope link  src 10.10.1.15  metric 203
10.10.1.2 dev eth1  scope link

And I try to add the following route

ip route add 127.22.0.0/16 via 10.10.1.2 dev eth1

But unfortunately it doesn’t work.

Here is the output

root@sys:/ # ip route flush cache
ip route flush cache
root@sys:/ # ip route get "127.22.0.1"
ip route get "127.22.0.1"
local 127.22.0.1 dev lo  src 127.0.0.1
    cache <local>

As you can see all packets are still redirected to loopback.

What is the best solution for that problem ?

Answer

As mentioned in What is the rest of the 127.0.0.0/8 address space used for? , the 127.0.0.0/8 block is the loopback block, and all packets destined to the block must be looped back to the origin host.

So, you cannot route those packets anywhere.

Attribution
Source : Link , Question Author : e109848 , Answer Author : Tero Kilkanen

Leave a Comment