Cannot route through an if without ip
I have an ethernet (eth1) without any assigned ip, nevertheless I would like to route through this IF but issueing the following command gives an error:
route add -net 192.168.1.0 dev eth1
If the same IF has an address the command will be correctly executed.
Why?
Quoted 8 lines · antonio.dibacco
I have an ethernet (eth1) without any assigned ip, nevertheless I would like to route through this IF but issueing the following command gives an error:
route add -net 192.168.1.0 dev eth1
If the same IF has an address the command will be correctly executed. Why?
You can't do that. If you know the mac of the other router, do domething like:
#ip ro add 172.20.20.20/32 dev eth1 scope link
#arp -s 172.20.20.20 <mac>
#ip ro add 192.168.1.0/24 via 172.20.20.20.20
So .. this just show why you can't just route throught an ethernet device, unless you "want" to do some multicast flood.
Hello,
Quoted 3 lines · antonio.dibacco
I have an ethernet (eth1) without any assigned ip, nevertheless I would like to route through this IF but issueing the following command gives an error:
route add -net 192.168.1.0 dev eth1
When I type this command I get an error because 192.168.1.0 is not a subnet, I must add a mask or prefix length, for instance :
route add -net 192.168.1.0/24 dev eth1
Quoted 2 lines
If the same IF has an address the command will be correctly executed. Why?
The interface has to be up and bound to IPv4. You can check this when directory /proc/sys/net/ipv4/conf/eth1 exists. To force this without assigning an address to the interface, just execute the following command :
ifconfig eth1 0.0.0.0 up
The default source address used in locally generated packets will be chosen among addresses assigned to other interfaces. You can assign it statically creating the route with 'ip' instead of 'route' :
ip route add 192.168.1.0/24 dev eth1 src $LOCAL_IP
where $LOCAL_IP is a local address assigned to any interface but the loopback.
Note there are possible issues regarding routing and ARP if you expect to receive IPv4 traffic on eth1.
- Routing : hosts on the network reachable on eth1 must have appropriate route(s) to the box addresse(s).
- ARP : your box must accept and reply to ARP requests about any local address received on eth1. For this, make sure the kernel parameters arp_filter, arp_announce and arp_ignore in /proc/sys/net/ipv4/conf/eth1 have appropriate value (default values 0 should be fine). Or you can add static ARP entries on the hosts reachable on eth1.
PS: Any feedback about my reply to your previous question ?