Skip to main content
3 of 6
Clarify and generalize.
BillThor
  • 9.1k
  • 24
  • 27

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 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 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 192.0.2.1 ip route del default via 10.0.0.1 route add default gw 192.0.2.1 route del default gw 10.0.0.1 

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.

BillThor
  • 9.1k
  • 24
  • 27