0

They say you can assign a whole ip subnet to an interface in Linux using this command:

ip -4 route add local 192.168.0.0/24 dev lo

It is described in multiple articles around internet, for example, here. This article even says you will see the new ip block if you issue an ip addr show command.

However this doesn't work for me in Debian 12 run as unprivileged LXC in Proxmox.

However in one place I've found that you can assign a subnet to the interface like this:

ip addr add 192.168.5.0/24 dev lo

The difference is you're specifying an address to the interface, not creating a route.

And it works!

root@networking:~# ip addr add 10.175.0.0/16 dev lo
root@networking:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet 10.175.0.0/16 scope global lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host noprefixroute 
       valid_lft forever preferred_lft forever
2: eth0@if13: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether bc:24:11:8a:ff:a7 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet etc etc...

If I specify the real ip as a Next Hop in the routing rules of my TP-Link Router to reach this 10.175.0.0/16 network I can ping it, and the programs I run on this machine will accept connections to any of the ip addresses in this subnet.

The non-working solutions is everywhere in the internet, and the working solution is buried here and has a warning comment that you should not do it, but you should follow a non-working solution.

While I'm currently relying on the second approach I am afraid I may face some problems in the future.

What am I missing? What works for you and why do you think the correct way doesn't work for me at all?

fedd
  • 101

1 Answers1

0

Stick with ip addr: Since adding the IP directly with ip addr add 192.168.5.0/24 dev lo works, you can just keep using that approach. It’s the easiest fix.

Check LXC Permissions: Make sure your LXC container has the right permissions to modify its network settings. Sometimes, LXC containers have restrictions that prevent certain changes.

Use ip rule for Routing: If you need to set up routes for the subnet inside the container, you could use policy-based routing with ip rule. For example:

ip rule add from 192.168.5.0/24 lookup 100 ip route add default via
192.168.5.1 dev lo table 100

This will let you handle routing more specific inside the container.

Kiyomizu
  • 126