multiple interfaces with different default gateways issue
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
multiple interfaces with different default gateways issue
Dear All,
I have installed CentOS 5.5 64 bit on servers. Server have two NICs so I got following IP address information for each NIC.
eth0
IP Address: 192.168.0.12
Subnet Mask: 255.255.255.0
Default Gateway: 192.168.0.1
eth1
IP Address: 192.168.0.13
Subnet Mask: 255.255.255.0
Default Gateway: 192.168.0.2
When I assign IP addresses to both NICs from Graphical interface and execute "route -n" command then it only shows 192.168.0.1. Whereas I have defined separate default gateways for both NICs. How to fix that?
Furthermore eth1 IP address is public and accessible over internet whereas eth0 is private on. How can I configure centos in this way.
I'll really appreciate prompt response in this regard.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
You can't have different default gateways while using the same subnet. It is nonsense to say that one of your cards is connected to the internet. The IP address of 192.168.0.13 can NOT be public, it is an address reserved for internal use.
I guess you have a router between the internet and said eth1. Since both cards are on the same subnet you have the gateways on the same subnet as well.
So point your default gateway to 192.168.0.2 as I assume that one is the router going to the internet.
For all other addresses which you want to go thru 192.168.0.1 you must set up a specific route:
Code:
route add -net 192.168.22.0/24 gw 192.168.0.1 dev eth0
Thanks for the help. I know the public IP Address 192.168.0.13 can't be public because it is reserved for internal use. I just mentioned dummy IP Addresses here.
Coming back to point, let me give more detail that in our lab we have two routers (cisco 6713(A), cisco 6713(B)). So NIC one has cable coming from router A and other NIC is getting cable from router B.
I believe this might be of some help to you provide suggestion/solution.
I am sorry if you don't like my following sentence. Actually I meant to say that as you guys response to my queries very fast so I was expecting same positive and helpful reply from you guys.
I hope it clarifies and you will help me in this matter.
First of all there are two basic thing you need to understand (and apply) when you post on LQ, patience and politeness. Sad to say you are not showing either. This will only result in users not being very willing to help you. We are all volunteers here who are helping out other Linux users on our free time. If you need 'urgent' help, then get paid assistance.
That being said, jlinkels already put you on track, that you have to base your routing on device level if you want to separate traffic or put your NICs in a different subnet.
# ip route
58.27.179.160/27 dev eth1 proto kernel scope link src 58.27.179.162
58.27.179.128/27 dev eth0 proto kernel scope link src 58.27.179.130
169.254.0.0/16 dev eth1 scope link
default via 58.27.179.161 dev eth1
===========================iptables-save===============
no output
I am not exactly clear on what the problem is, or what you are trying to accomplish. Can you please try to summarise the problem in a few sentences please?
It looks like you have two interfaces, in seperate subnets, both with public IP ranges, there is no issue with your routing table right now, you can only have one default gateway set at a time as was mentioned earlier.
Let me summarize what I want to do. I have two servers having CentOS 5.5 installed. Both server has two NICs. The assignment of IP addresses is as follows (I will be mentioning dummy IPs due to security concerns).
Server 1:
NIC 1
IP Address: 192.168.0.12
Subnet Mask: 255.255.255.224
Default Gateway: 192.168.0.1
NIC 2
IP Address: 192.168.0.60
Subnet Mask: 255.255.255.224
Default Gateway: 192.168.0.161
Server 2:
NIC 1
IP Address: 192.168.0.13
Subnet Mask: 255.255.255.224
Default Gateway: 192.168.0.1
NIC 2
IP Address: 192.168.0.61
Subnet Mask: 255.255.255.224
Default Gateway: 192.168.0.161
Now I can access both servers through NIC 1 IP address (ssh 192.168.0.13) but when I try to access server using NIC 2 IP address as ssh 192.168.0.61 or ssh 192.168.0.60 then it says connection timed out. When I execute route -n it shows default gateway of NIC 2 (192.168.0.161). Now I want to know how can I access servers using NIC 2 IP addresses. Am I required to add some static routes? If yes then please refer me to some tutorial or tell me commands to do that.
I hope now it will be much easier for you to understand my issue and help me to resolve the issue.
You CAN NOT assign IP from the same subnetwork to a different interfaces on the same box. Internal router wont work.
Server 1 should has:
NIC 1
IP Address: 192.168.1.xxx
Subnet Mask: 255.255.255.xxx
Default Gateway: 192.168.1.1
NIC 2
IP Address: 192.168.5.xxx
Subnet Mask: 255.255.255.xxx
Default Gateway: 192.168.5.1
You really have to remember what SuperJediWombat! said:
YOU CANNOT HAVE TWO DEFAULT GATEWAYS!!!
That way you understand that there are some things that you can't do with simple routing.
Simply routing (route command or GUI) only route packets based on destination ip.
If you want to route a packet based on another stuff, you can not do it with simple routing.
For example if you want your packet to get routed based on source ip, there's something called source routing using iproute2 (I think). So put clear what factor is the base of your routing and there you can google it of post it here again.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.