Search This Blog

Wednesday, July 2, 2008

To configure routing or add route

You can use route command to configure routing. Syntax is as follows:
route add net {network-address} netmask {subnet} {router-address}

Let us assume your router address is and network ID is, then you can type route command as follows:
# route add net netmask


To add a default route:
# route add default

Verify that (display) routing table is updated (display routing table):
# netstat -nr

Test it i.e. try to ping or send nslookup request:
# ping

To flush all routing entries use command [quite handy to clean your gordian knot ;)] :
# route -f

However if I reboot HPUX box then above routing entries gets removed. To pick up your setting upon each reboot your need to configure Routes in HPUX networking configuration file - /etc/rc.config.d/netconf. To add default router/gateway
# vi /etc/rc.config.d/netconf

Add or modify following entries


Reboot HP-UX system/server to take effect
# shutdown -ry 0 Someone might attack on your system. You can drop attacker IP using IPtables. However, you can use route command to null route unwanted traffic. A null route (also called as blackhole route) is a network route or kernel routing table entry that goes nowhere. Matching packets are dropped (ignored) rather than forwarded, acting as a kind of very limited firewall. The act of using null routes is often called blackhole filtering.

You can nullroute (like some time ISP do prevent your network device from sending any data to a remote system.) stopping various attacks coming from a single IP (read as spammers or hackers):

Nullroute IP using route command

Suppose that bad IP is, type following command at shell:

# route add gw lo

You can verify it with following command:
# netstat -nr
# route -n
You can also use reject target (thanks to Gabriele):
# route add -host IP-ADDRESS reject
# route add -host reject

To confirm the null routing status, use ip command as follows:
# ip route get

RTNETLINK answers: Network is unreachable

Drop entire subnet
# route add -net gw lo
You can also use ip command to null route network or ip, enter:
# ip route add blackhole
# route -n

How do I remove null routing? How do I remove blocked IP address?

Simple use router delete command,
# route delete
This is cool, as you do not have to play with iptables rules.

Q. How do I setup default gateway with a route command?

A. route command show and/or manipulate the IP routing table under Linux and UNIX oses.

Route manipulates the kernel's IP routing tables. Its primary use is to set up static routes to specific hosts or networks via an interface after it has been configured with the ifconfig program. When the add or del options are used, route modifies the routing tables. Without these options, route displays the current contents of the routing tables.

Display default route

Following three-command display the current routing table:
# route

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface     *        U     0      0        0 ra0
default         dsl-router         UG    0      0        0 ra0

$ /sbin/route

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface   *        U     0      0        0 eth0     *          U     0      0        0 eth0
default         UG    0      0        0 eth0

You can use -n option, to display numerical addresses instead of trying to determine symbolic host names (via dns or /etc/hosts file). This is useful if you are trying to determine why the route to your nameserver has vanished.$ /sbin/route -nOutput:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface   U     0      0        0 venet0     U     0      0        0 venet0         UG    0      0        0 venet0

Please note that a destionation entry (or default) is the default gatway. In above example is a default gatway.

Add / setup a new route

The syntax is as follows:
route add default gw {IP-ADDRESS} {INTERFACE-NAME}


  • IP-ADDRESS: Specify router IP address
  • INTERFACE-NAME: Specify interface name such as eth0

For example if your router IP address is type the following command as the root user:
# route add default gw eth0OR use hostname such as dsl-router:# route add default gw dsl-router eth0

Setting route using GUI tools/command under Linux

If you find above command hard to use, consider using GUI tools. If your are using Red Hat/CentOS/Fedora core Linux type following command:# redhat-config-networkOR If you are using other Linux distribution use command:# network-admin

No comments: