Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Currently I'm running a FreeBSD 9.1 and the default gateway is already configured in the rc.conf.


defaultrouter = ""

But now I want to change the default gateway without rebooting the system, is this possible?

share|improve this question

migrated from serverfault.com Aug 21 '13 at 2:02

This question came from our site for system and network administrators.

6 Answers 6

up vote 7 down vote accepted
route del default
route add default

Where is the new gateway. You can even concatenate them onto the same line with a ;

Edit: This is FreeBSD, not Linux. The command is different. Please do not edit this Answer if you haven't read the Question carefully enough to determine the operating system being used.

share|improve this answer
+1 for the semi-colon trick ;) –  msw Aug 21 '13 at 3:55
Note: do this in console, not over ssh. If you must do this via ssh (or other network method), issue both commands at once, with ; or with && –  Dalibor Filus Jul 8 '14 at 14:58

You can add a new default route and remove the old one using either the ip or route command. The above commands will replace the gateway with Both command pairs do the same thing. FreeBSD and other OSs should have one or both programs, possibly with slightly different formats. (FreeBSD has the route command and excludes gw in its format.) The commands man ip and/or man route should provide you with documentation on your specific implementation.

ip route add default via
ip route del default via 

route add default gw
route del default gw

Change to your desired default gateway. The default gateway needs to be on one of networks you have a direct connection to. You can change your IP address in a similar manner. ip is a newer tool which will do most everything you need to do to view and manage IP addresses and routing on IPv4 and IPv6 networks. ifconfig is an an older tool for configuring IP addresses on an IPv4 network.

To make the change permanent, update your network configuration files in /etc. The file(s) vary depending on the distribution you are using.

At least one of these commands should be available on any Unix derived O/S. Different versions may work slightly differently. Check the man page for details on your O/S.

share|improve this answer
-1 Sorry, but these are Linux commands and don't work on FreeBSD. –  Chris S Aug 21 '13 at 1:59

yes just change the route and restart your network.

/etc/rc.d/netif restart
share|improve this answer
That works, though it restarts a heck of a lot... and might break applications that are bound to interfaces. –  Chris S Aug 21 '13 at 1:59

It's very easy, you only need to type the next commands:

$ route del 0/0
$ route add 0/0

You gonna need to replace the '' with the IP of your choice.

And to check the changes you can use 'netstat':

$ netstat -r

This command show the routing table of the system.

Hope this help you.

share|improve this answer
What is "0/0" ? –  WWW Aug 21 '13 at 15:20
@WWW '0/0' is the abbreviation of the network block '', which is the same as 'default', but I prefer '0/0' (I suppose i'm more of the old school). –  ifm Aug 21 '13 at 17:23

Here's a one-liner:

ip route replace default via

Where is the new gateway IP


share|improve this answer
-1 Sorry, but these are Linux commands and don't work on FreeBSD. –  Chris S May 22 at 15:49

You could try:

route add default gw eth0
share|improve this answer
-1 Sorry, but these are Linux commands and don't work on FreeBSD. –  Chris S May 22 at 15:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.