Default gateway on different subnet (linux case)

Linux specific questions/information are gathered here. The main thrust of topics are applied to Centos/RedHat(RH)/Debian/Ubuntu/Gentoo distributives

Default gateway on different subnet (linux case)

Postby lik » Wed Aug 15, 2012 3:23 pm

By default linux distributions (not only) expect that default gateway IP address belongs to configured subnetwork on the interface and is not a broadcast address.
As a result we will receive the following error trying to define gateway outside of configured network:
Code: Select all
# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:16:3E:29:5A:82 
          inet addr:10.10.10.10  Bcast:10.10.10.15  Mask:255.255.255.248
          inet6 addr: fe80::216:3eff:fe29:5a82/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2522216 errors:0 dropped:0 overruns:0 frame:0
          TX packets:61813 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:185056341 (176.4 MiB)  TX bytes:122461673 (116.7 MiB)
          Interrupt:77

# route add default gw 11.11.11.11
SIOCADDRT: No such process

****
To resolve it we can use the following way:
Code: Select all
route add 11.11.11.11/32 dev eth0
route add default gw 11.11.11.11

If we want to make above routes persistent we should define them in network init script:
Debian/Ubuntu case:
Add the following rules in /etc/network/interfaces :
Code: Select all
post-up route add 11.11.11.11/32 dev eth0
post-up route add default gw 11.11.11.11

RedHat/Centos case:
Add the following rule in /etc/sysconfig/network-scripts/ifcfg-eth0
Code: Select all
SCOPE="peer 11.11.11.11"
lik
Founder
Founder
 
Posts: 497
Joined: Wed Dec 15, 2010 3:21 am

Default gateway on different subnet (freebsd case)

Postby lik » Thu Dec 13, 2012 11:21 pm

FreeBSD case:

Code: Select all
/sbin/route add -host 11.11.11.11 -iface rl0
/sbin/route add default 11.11.11.11


To make these routes persistent define them in /etc/rc.conf :
Code: Select all
ifconfig_em0="inet 10.10.10.10 netmask 255.255.255.248"
static_routes="net1 net2"
route_net1="-net 11.11.11.11/32 -iface em0"
route_net2="default 11.11.11.11"

or even:
Code: Select all
ifconfig_em0="inet 10.10.10.10 netmask 255.255.255.248"
static_routes="net1"
route_net1="-net 0.0.0.0/0 -iface em0"
lik
Founder
Founder
 
Posts: 497
Joined: Wed Dec 15, 2010 3:21 am


Return to Linux specific

 


  • Related topics
    Replies
    Views
    Last post
cron