# routing table setup issue

## Cr0t

I have two nics, which are connected to the same switch. They are both talking to the same dhcp server, but I want only one to be used for the local network and the other one just for going out.

```
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 eth0

0.0.0.0         192.168.0.1     0.0.0.0         UG        0 0          0 eth1

127.0.0.0       127.0.0.1       255.0.0.0       UG        0 0          0 lo

192.168.0.0     0.0.0.0         255.255.255.240 U         0 0          0 eth0

192.168.0.0     0.0.0.0         255.255.255.240 U         0 0          0 eth1
```

Let's make eth0 just for local 192.168.0.0/255.255.255.240 and eth1 for outgoing.

```

route del default gw 192.168.0.1 dev eth0

route del -net 192.168.0.0 netmask 255.255.255.240 dev eth1
```

The routing table gets cleaned up as expected, but the traffic is not working as expected.

ping'ing is super slow.

Got any advice?

----------

## papahuhn

Try 

echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore

----------

## Hu

Connecting two NICs to the same switch is possible, but is rarely the right solution.  Could you explain why you are doing this instead of bonding the NICs?

----------

## Cr0t

 *papahuhn wrote:*   

> Try 
> 
> echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore

 No difference.

----------

## wmark

What is the output of:

```
ip -4 addr

ip -4 route

sysctl -a | grep -F 'forward'
```

----------

## Cr0t

 *wmark wrote:*   

> What is the output of:
> 
> ```
> ip -4 addr
> 
> ...

 Original:

```
20:43:19^root@ninapie:~ > ip -4 addr 

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 

    inet 127.0.0.1/8 scope host lo

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

    inet 192.168.0.3/28 brd 192.168.0.15 scope global eth0

3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

    inet 192.168.0.5/28 brd 192.168.0.15 scope global eth1

20:43:28^root@ninapie:~ > ip -4 route 

default via 192.168.0.1 dev eth0  metric 202 

default via 192.168.0.1 dev eth1  metric 203 

127.0.0.0/8 via 127.0.0.1 dev lo  scope link 

192.168.0.0/28 dev eth0  proto kernel  scope link  src 192.168.0.3  metric 202 

192.168.0.0/28 dev eth1  proto kernel  scope link  src 192.168.0.5  metric 203 

20:43:28^root@ninapie:~ > sysctl -a | grep -F 'forward'

net.ipv4.conf.all.forwarding = 0

net.ipv4.conf.all.mc_forwarding = 0

net.ipv4.conf.default.forwarding = 0

net.ipv4.conf.default.mc_forwarding = 0

net.ipv4.conf.lo.forwarding = 0

net.ipv4.conf.lo.mc_forwarding = 0

net.ipv4.conf.eth0.forwarding = 0

net.ipv4.conf.eth0.mc_forwarding = 0

net.ipv4.conf.eth1.forwarding = 0

net.ipv4.conf.eth1.mc_forwarding = 0

net.ipv4.ip_forward = 0
```

after... route del default gw 192.168.0.1 dev eth0 

route del -net 192.168.0.0 netmask 255.255.255.240 dev eth1

```
20:44:32^root@ninapie:~ > ip -4 addr 

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 

    inet 127.0.0.1/8 scope host lo

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

    inet 192.168.0.3/28 brd 192.168.0.15 scope global eth0

3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

    inet 192.168.0.5/28 brd 192.168.0.15 scope global eth1

20:44:42^root@ninapie:~ > ip -4 route 

default via 192.168.0.1 dev eth1  metric 203 

127.0.0.0/8 via 127.0.0.1 dev lo  scope link 

192.168.0.0/28 dev eth0  proto kernel  scope link  src 192.168.0.3  metric 202 

20:44:42^root@ninapie:~ > sysctl -a | grep -F 'forward'

net.ipv4.conf.all.forwarding = 0

net.ipv4.conf.all.mc_forwarding = 0

net.ipv4.conf.default.forwarding = 0

net.ipv4.conf.default.mc_forwarding = 0

net.ipv4.conf.lo.forwarding = 0

net.ipv4.conf.lo.mc_forwarding = 0

net.ipv4.conf.eth0.forwarding = 0

net.ipv4.conf.eth0.mc_forwarding = 0

net.ipv4.conf.eth1.forwarding = 0

net.ipv4.conf.eth1.mc_forwarding = 0

net.ipv4.ip_forward = 0
```

----------

## wmark

eth0 is for the LAN, all outgoing connections are to be routed through eth1, the gateway is 192.168.0.1 and we're on network layer.

The problem is that both are in the same subnet - and even on the same switch.

You have to prevent eth1 from being used for data to the LAN. You can achieve that by modifying its CIDR to /32.

Unfortunately the gateway won't be in the same subnet anymore - therefore we configure it being a peer to (port) eth1.

I am not sure whether this is necessary, but it will do no harm: We add an route to the gateway just to be sure eth1 is used.

In case the machine in question acts as router you will have to activate forwarding, so that packets from eth0 are routed through eth1 to the gateway ("sysctl -w net.ipv4.ip_forward=1").

eth0's configuration can be left unchanged. This is due to the routing policy "longest prefix match first" - although the gateway is in the same LAN as eth0, the route we created by the step mentioned above will have a longer subnet prefix (/32). Remember that a "default" route is used as fallback, i.e. if nothing else matched.

Expunge and prune your configuration (issue commands "ip addr del..." and "ip route del..." as well as "arp -d ...") and run:

```
ip addr add 192.168.0.3/28 dev eth0

ip addr add 192.168.0.5/32 dev eth1 peer 192.168.0.1

ip route add default via 192.168.0.1 dev eth1
```

/etc/conf.d/net should look like this:

```
modules=( "iproute2")

config_eth0=("192.168.0.3/28")

config_eth1=("192.168.0.5/32 peer 192.168.0.1")

routes_eth1=("default via 192.168.0.1")

dns_servers_eth0=(....)

```

That should do the trick. If so, please prepend [solved] to this thread's topic, else please post the output of "ip -4 addr list" and "ip -4 route list" again.  :Wink: 

----------

