Setting up two NICs on two separate LANs provides error

7,568

That guide is convoluted and not the standard way to do it in CentOS.

You aren't specifying the netmask so I guess it is assuming a class A based on the IP address, in which case they are on the same subnet and the second route command would replace the first. Run ip addr ls, ifconfig, route -n, or netstat -rn to see.

Now, I'm not sure what you are trying to do but it is best to take it in steps. First, you configure the interfaces then you add your routing. The CentOS method for configuring the interfaces is to edit /etc/sysconfig/network-scripts/ifcfg-eth0 and ifcfg-eth1. You configure your default route in /etc/sysconfig/network. You configure additional routes in /etc/sysconfig/network-scripts/route-eth0 and route-eth1.

Here are my assumptions. Change to match your setup. The IP addrs of your CentOS box are 10.2.0.20 for eth0 and 10.1.0.20 for eth1. The netmask for both is 255.255.255.0. The gateway for eth0 is 10.2.0.1 and the gateway for eth1 is 10.1.0.1. You want all traffic to go through eth0 except 10.1.0.0/24 and 10.3.0.0/24 which go through eth1.

In ifcfg-eth0 you have:

DEVICE=eth0
IPADDR=10.2.0.20
NETMASK=255.255.255.0
BOOTPROTO=static
ONBOOT=yes

In ifcfg-eth1 you have:

DEVICE=eth1
IPADDR=10.1.0.20
NETMASK=255.255.255.0
BOOTPROTO=static
ONBOOT=yes

In /etc/sysconfig/network you have:

NETWORKING=yes
HOSTNAME=whatever
GATEWAY=10.2.0.1

In /etc/sysconfig/network-scripts/route-eth1 you have:

10.3.0.0/24 via 10.1.0.1
Share:
7,568
Aeo
Author by

Aeo

Updated on September 17, 2022

Comments

  • Aeo
    Aeo almost 2 years

    I wish I had found this before starting in, but it's too late for that...


    I am running CentOS 5.5.

    I started following this guide for setting up two NICs on different networks. Everything was going fine until I hit this step:

    This part allow the routing to the direct neigbor over the good interface :

    ip route add 10.2.0.0 dev eth0 src 10.2.0.1
    ip route add 10.1.0.0 dev eth1 src 10.1.0.1

    I am hit with the following error when I try to do those commands:

    RTNETLINK answers: Invalid argument

    I am not very experienced in server setup. However, I have been tasked to do this, so I look for help. Any suggestions on where to go from here?

    Alternatively, any suggestions on how to undo what I have done so far, in order to give the other guide listed above a try?


    Edit: I forgot to mention, this server also has the tool Webmin installed, if that should help any.

    • Admin
      Admin almost 14 years
      you need to setup 2 default routes to use 2 ISPs to connect to internet like in the guide? or only 2 NICs to have access to 2 networks like a normal router? To undo you only need to remove the modifications you made to rt_table (optional but I would prefer to do it) and restart the server or network (not sure how to do this on CentOS but on Ubuntu it's /etc/init.d/networking restart) as if you followed the guide, the modifications are not persisted.
    • Admin
      Admin almost 14 years
      On CentOS it's (as root) service network restart (or /etc/init.d/network restart)
    • Admin
      Admin almost 14 years
      Thanks for the info on undoing it. That will certainly ease my tensions about this whole thing. As for the 2 ISPs, bit more complicated than that. eth0 has access to the internet. eth1 also has access to the internet, but I would prefer it didn't. eth0 is the interface we will be serving pages over, and eth1 will be the internal office network. They are two different LANs entirely, however should never need to serve anything up over eth1. The objective of this is to increase FTP speeds. We had been uploading to the servers over the internet which slowed the whole office down.
  • Aeo
    Aeo almost 14 years
    I don't really know if it's a typo or not. I know just enough about networking to adapt the schema to fit our network setup. Beyond that, it's all educated guessing. Feel free to correct me if I'm wrong, but would not switching those two IPs actually confuse the two separated sides?