LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Confusion about the "GATEWAY=x.x.x.x" attribute (https://www.linuxquestions.org/questions/linux-networking-3/confusion-about-the-gateway%3Dx-x-x-x-attribute-65043/)

glock19 06-11-2003 04:21 PM

Confusion about the "GATEWAY=x.x.x.x" attribute
 
In Red Hat Linux 9, in the "/etc/sysconfig/network" file, you can have a line "GATEWAY=x.x.x.x". Question, is this the default gateway for the server?

Also, another question about that same file, "/etc/sysconfig/network", what is the purpose of the line "GATEWAYDEV=ethx"? In the case that the server has 2 NICs, there can be a gateway for only 1 of the NICs? Why can't each NIC have it's own gateway?

Also, I noticed that some people (based on a google search) are putting the "GATEWAY=x.x.x.x" statement in their "/etc/sysconfig/network-scripts/ifcfg-ethx" file. Is this a valid setup? I mean, shouldn't the gateway setting be in either one or the other, but not in both? And doesn't it make more sense to put the gateway in the "/etc/sysconfig/network" file?

Also, if it's true that, on a 2 NIC server, that only 1 of the NICs can have a default gateway, then what happens to the other NIC? It just doesn't get a default gateway? That seems wrong...

I hope there are some networking gurus who can help clear this confusion for me (and hopefully for anyone else who is reading this thread who wondered the same thing). Thanks!

peter_robb 06-11-2003 05:11 PM

Ok,
there are several ways to implement the default gateway... as you can see...
The /etc/sysconfig/network file is read first.
If an entry is there, it is used.
Gateway dev refers to dynamically allocated numbers where Gateway=x.x.x.x means nothing, but it is always going to use that interface, eg ppp0, eth1 etc.
eg a VPN connection with a dynamic number always through eth2

Putting the gateway number in the interface config file /etc/sysconfig/network-scripts/ifcfg~ means that the gateway number only appears after the interface is up, so if you have many network connections (or settings) possible, the correct one will be used.
My machine has the ability to use 3 different default gateways by selecting which eth~ I bring up. Each has a different gateway number but the same static ip number on the card.
I use this for fallback when an external route is down, a slower one is used as default.

You can have several default gateways in the routing table, but the first one in the list is used.

Separate networks have their own gateways defined by the addresses of the network. Once the routing table knows which network the packet belongs to, it will find the gateway that matches and use that.
The default gateway is the last choice, when nothing else matches.

glock19 06-11-2003 06:23 PM

Quote:

Originally posted by peter_robb
Ok,
there are several ways to implement the default gateway... as you can see...
The /etc/sysconfig/network file is read first.
If an entry is there, it is used.
Gateway dev refers to dynamically allocated numbers where Gateway=x.x.x.x means nothing, but it is always going to use that interface, eg ppp0, eth1 etc.
eg a VPN connection with a dynamic number always through eth2

Let me see if I understand. I should not put the Gateway=x.x.x.x in the /etc/sysconfig/network file?

And the only point of the Gateway dev is to lock down which interface the gateway will always be using? So this is an optional statement?


Quote:

Originally posted by peter_robb

Putting the gateway number in the interface config file /etc/sysconfig/network-scripts/ifcfg~ means that the gateway number only appears after the interface is up, so if you have many network connections (or settings) possible, the correct one will be used.
My machine has the ability to use 3 different default gateways by selecting which eth~ I bring up. Each has a different gateway number but the same static ip number on the card.
I use this for fallback when an external route is down, a slower one is used as default.

You can have several default gateways in the routing table, but the first one in the list is used.

Separate networks have their own gateways defined by the addresses of the network. Once the routing table knows which network the packet belongs to, it will find the gateway that matches and use that.
The default gateway is the last choice, when nothing else matches.

So if I have interface A, on network 192.168.200.0 and I also have interface B, on network 192.168.168.0, then I can have two default gateways. Let's assume that the default gateway for interface A is first, and then after is the default gateway for interface B. Then, when a packet is destined for somewhere in 192.168.168.0 land, it will pass over the first default gateway since it doesn't match? Or will it just attempt to send out on the first default gateway, even though it's not a matching network?

peter_robb 06-12-2003 04:54 AM

Gateway=x.x.x.x in the /etc/sysconfig/network file is the standard way of entering the default Gateway address.
This address is used if packet destinations don't match anything local.

A Gateway is a router that attaches to a distant network

If you have two networks, & both of them have access to the internet, you can have two Gateway settings, but only the first will be used.
Which is first? Look in the routing table... route -n

Again place the number either in /etc/sysconfig/network or in the ifcfg-eth~ files.
It depends on how dynamic your network becomes.
I do a lot of testing so mine is very dynamic and I use the ifcfg-eth~ files.

In your routing tables, you can specify direct routes, so that packets for say a specific smtp server go down eth1 and the rest go down eth2, eg
route add host mx1.hotmail.com gw 192.168.168.x
route add default gw eth2


man route for more examples...

In a lot of ways however, it is better to use iptables DNAT to start splitting hosts or services or ports into different routes.
There are many more filter criteria there.

glock19 06-12-2003 12:18 PM

Quote:

Originally posted by peter_robb
If you have two networks, & both of them have access to the internet, you can have two Gateway settings, but only the first will be used.
Which is first? Look in the routing table... route -n

Ok, I guess this is the last part that is confusing me. What is the point of having two gateways, if only the first one is ever used?

peter_robb 06-13-2003 08:18 AM

Choice...
I send ftp and email traffic on one, browsing etc on the other.
Anything that can be 'set and forget' I don't put on my fast connection. I leave that free for browsing, chat, ssh, admin etc where I can get high response speeds and low congestion.
The ftp and mail can take their time, no problem to me...
Users doing kazaa etc will always get the slowest link out. Lots of congestion from those services!

Also, it is possible to have a cable connection and a dial-up both working at the same time, so which one do you use?
Which makes your question very appropriate...!

So I have a separate set of iptables rules and routing additions for ppp~ to handle both connections.


All times are GMT -5. The time now is 09:19 PM.