Tuesday, August 11, 2009

How can I change my default gateway in Linux?

How can I change my default gateway in Linux?


Your machine needs to have a single default gateway. DHCP servers will automatically assign a default gateway to DHCP configured NICs, but NICs with configured static IP addresses will need to have a manually configured default gateway. This can be done with a simple command.

[root@linux etc]# route add default gw 192.168.1.1 eth0

In this case, make sure that the router/firewall with IP address 192.168.1.1 is connected to the same network as interface eth0!

Once done, you’ll need to update your /etc/sysconfig/network file to reflect the change. This file is used to configure your default gateway each time Linux boots.

NETWORKING=yes
HOSTNAME=linux
GATEWAY=192.168.1.1

How to delete a route in Linux?

How to delete a route in Linux?



Here’s how to delete a route for the network 10.0.0.0/8 with a gateway of 192.168.1.254 connected to the interface eth0.

[root@linux etc]# route del -net 10.0.0.0 netmask 255.0.0.0 gw 192.168.1.254 eth0

The file /etc/sysconfig/network-scripts/route-eth0 will also have to be updated so that when you reboot the server will not reinsert the route. Delete the line that reads:

10.0.0.0/8 via 192.168.1.254

How can I enable or disable an Ethernet interface in Linux?

How can I enable or disable an Ethernet interface in Linux?


The ifup and ifdown commands can be used respectively to activate and deactivate a NIC interface. You must have an ifcfg file in the /etc/sysconfig/network-scripts directory for these commands to work.

Here is an example for interface eth0:

To shutdown eth0:
[root@linux etc]# ifdown eth0

To enable eth0:
[root@linux etc]# ifup eth0

To make the change permanent, modify the interface config in the /etc/sysconfig/network-scripts directory. It will be named ifcfg-[interface], i.e. ifcfg-eth0 for Ethernet 0.

Open the file in your favorite editor and change:

ONBOOT=yes

to

ONBOOT=no

 
Things You Should Know About Linux !!!