Currently I'm running a FreeBSD 9.1 and the default gateway is already configured in the
defaultrouter = "10.0.0.1"
But now I want to change the default gateway without rebooting the system, is this possible?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
route del default route add default 184.108.40.206
220.127.116.11 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.
You can add a new default route and remove the old one using either the
route command. The commands below will replace the gateway with 192.0.2.1. 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 the
gw keyword used in other implementations.) The commands
man ip and/or
man route should provide you with documentation on your specific implementation.
route add default 192.0.2.1 route del default 10.0.0.1 ip route add default via 192.0.2.1 ip route del default via 10.0.0.1
There are multiple implementations of these commands, so the above may not match your implementation. Your implementation should have a
man page with examples for common use cases such as adding and removing default gateways. Try
man route and
man ip to see how your implementation works.
Change 192.0.2.1 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.
(EDIT: this may be useful if you're on Linux, but the OP asked about FreeBSD)
Here's a one-liner:
ip route replace default via 18.104.22.168
22.214.171.124 is the new gateway IP