Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In FreeBSD, an ifconfig call seems to delete the default gateway route, even when given the same IP-address (e.g. when updating the netmask only). Is it a bug or a feature?
As fas as I remember Linux doesn't change the default gateway in this case.

share|improve this question
up vote 4 down vote accepted

In FreeBSD an ifconfig that removes direct connectivity to a subnet also zaps routes containing that subnet (IIRC updating netmasks is reduced to a remove-and-replace). This is a "feature" so as not to confuse your routing configuration by trying to talk to a host it can't reach anymore, though it causes its share of confusion when users encounter disappearing routes.

See also:

share|improve this answer
Thanks. This is something to keep in mind when running ifconfig on a remote host. – eugene y Jun 14 '10 at 18:58
Oh yes - I've been bitten enough times that I now set a safety reboot (shutdown -r +10) before doing any network-affecting stuff on a remote host. Great if you trust the machine to reboot correctly since if you break something it will come back with its boot-time config pretty quickly :) – voretaq7 Jun 14 '10 at 21:29

I believe this happens because the ifconfig command is actually deleting the old IP and creating the new one, not just changing it. "It's a feature!"

share|improve this answer

I was looking for a way to keep the route to default gw in place, but since I saw this thread and tried on my own I guess there's no way. The only thing I had to do is set default gw manually right after setting the ip:

sudo ifconfig eth0 subnet
sudo route add default gw

so keep in mind if you're doing this remotely better run both commands with && or you'll get stuck out

sudo ifconfig eth0 subnet && sudo route add default gw
share|improve this answer

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.