0

Lets say my router has a LAN (192.168.0.1/24) and a DMZ (192.168.1.1/24). My computer has 2 NICs, one for LAN and one for DMZ.

How can I configure my routes so that it uses both gateways instead of a default one?

Output of ifconfig:

eth0      Link encap:Ethernet  HWaddr 00:15:17:6f:94:44
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:458357 errors:0 dropped:0 overruns:0 frame:0
          TX packets:250537 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:646967588 (616.9 MiB)  TX bytes:33742301 (32.1 MiB)
          Interrupt:16 Memory:fc3e0000-fc400000

eth1      Link encap:Ethernet  HWaddr 00:1e:4f:13:31:b7
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5 errors:0 dropped:0 overruns:0 frame:0
          TX packets:37 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:320 (320.0 B)  TX bytes:2992 (2.9 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:18979 errors:0 dropped:0 overruns:0 frame:0
          TX packets:18979 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:10059282 (9.5 MiB)  TX bytes:10059282 (9.5 MiB)

tap103i0  Link encap:Ethernet  HWaddr 3e:fb:b1:e0:40:da
          inet6 addr: fe80::3cfb:b1ff:fee0:40da/64 Scope:Link
          UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1
          RX packets:520 errors:0 dropped:0 overruns:0 frame:0
          TX packets:766 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:500
          RX bytes:44796 (43.7 KiB)  TX bytes:702165 (685.7 KiB)

vmbr0     Link encap:Ethernet  HWaddr 00:15:17:6f:94:44
          inet addr:192.168.0.2  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::215:17ff:fe6f:9444/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:437651 errors:0 dropped:0 overruns:0 frame:0
          TX packets:245697 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:637230824 (607.7 MiB)  TX bytes:31203868 (29.7 MiB)

vmbr1     Link encap:Ethernet  HWaddr 00:1e:4f:13:31:b7
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::21e:4fff:fe13:31b7/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5 errors:0 dropped:0 overruns:0 frame:0
          TX packets:34 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:230 (230.0 B)  TX bytes:2412 (2.3 KiB)

Output of netstat -rn:

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG        0 0          0 vmbr0
192.168.0.0     192.168.0.1     255.255.255.0   UG        0 0          0 vmbr0
192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 vmbr0
192.168.1.0     192.168.1.1     255.255.255.0   UG        0 0          0 vmbr1
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 vmbr1

/etc/network/interfaces:

auto lo
iface lo inet loopback

iface eth0 inet manual

iface eth1 inet manual

auto vmbr0
iface vmbr0 inet static
        address 192.168.0.2
        netmask 255.255.255.0
        gateway 192.168.0.1
        bridge_ports eth0
        bridge_stp off
        bridge_fd 0
        post-up route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.0.1


auto vmbr1
iface vmbr1 inet static
        address 192.168.1.2
        netmask 255.255.255.0
        gateway 192.168.0.2
        bridge_ports eth1
        bridge_stp off
        bridge_fd 0
        post-up route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1
  • What are you trying to achieve by using 2 gateways? are you trying to load balance traffic across both nics? are you wanting to pass local traffic to the lan, and non-local traffic through the DMZ? – Tim Kennedy Apr 22 '16 at 16:56
  • I'm trying to have DMZ facing VMs and internal VMs. – Jaden Wang Apr 22 '16 at 17:17
1

If you're needing it to use different default routes based on which local IP address is being used, this is where iproute2 comes into play.

https://www.thomas-krenn.com/en/wiki/Two_Default_Gateways_on_One_System

0

You can modify the /etc/network/interfaces file and add this line to each network interface stanza/block to define the static routes

# this is for vmbr0 block below
post-up route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.0.1

# this is for vmbr1 block below
post-up route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1

and you need to restart networking subsytem/service by service networking restart

OR

You can change the routing dynamically, but you will lose them when you reboot. It is good for testing purposes or for short term use.

route add -net 192.168.0.0/24 gw 192.168.0.1 dev vmbr0
route add -net 192.168.1.0/24 gw 192.168.1.1 dev vmbr1

This does not require you to restart networking, although it might cause a momentary disruption or session losses due to network switchover, when and where necessary.

  • Thanks for replying. I added the lines in my interface and restarted networking. Routes seem to look normal now. However, ping -I vmbr1 192.168.1.1 and ping -I vmbr1 google.ca both don't return anything. – Jaden Wang Apr 22 '16 at 17:18
  • what do you see as an output to netstat -rn command ? – MelBurslan Apr 22 '16 at 17:27
  • Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 vmbr0 192.168.0.0 192.168.0.1 255.255.255.0 UG 0 0 0 vmbr0 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 vmbr0 192.168.1.0 192.168.1.1 255.255.255.0 UG 0 0 0 vmbr1 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 vmbr1 – Jaden Wang Apr 22 '16 at 18:58
  • could you please update your original post with this information? Without the line breaks, it is very hard to follow. – MelBurslan Apr 22 '16 at 19:29
  • Updated, I don't post here very often so I'm not very good at formatting. – Jaden Wang Apr 22 '16 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.