FreeBSD-11.2 routing and networks

Mike Tancsa mike at sentex.net
Mon Jan 7 21:15:54 UTC 2019


On 1/7/2019 10:55 AM, James B. Byrne via freebsd-questions wrote:
> I am working on a FreeBSD-11.2p17 host where I must change the IP
> address and gateway frequently to carry out tests.  Following making
> such changes I have tried resetting the network interfaces and routing
> tables by use of the command:
>
> service netif restart && service routing restart &
>
> However, I have discovered that this does not have the desired effect
> and I am reduced to restarting the host system to make such changes. 
> Is there something else I should be doing?

If the two networks are on the same vlan, Its probably easier to just
manually use route and ifconfig. Also, when you change the IP (assuming
you dont have another nic on a connected interface that you are logging
in from), your network connection via ssh will drop.  Remember, packets
always follow a more specific route.  So lets say under normal
circumstances your machine is

10.1.1.2/24 with a gw of 10.1.1.1 and you are logged in from 172.29.13.1.

your test network is

192.168.1.2/24 with a gw of 192.168.1.1.


Rather than restart the network and delete the existing IPs from the
interface,

just do
route add 172.29.13.0/24 10.1.1.1

ifconfig <inteface> 192.168.1.2/24 alias
route change default 192.168.1.1

where interface is whatever your nic is (igb0,em0,re0 etc)...

This way you still have a path back to your machine you are logged into,
assuming 10.1.1.0/24 is still on the same vlan as your test IPs.. When
you want to revert, route change default 10.1.1.1 and ifconfig
<interface> 192.168.1.2/24 -alias


    ---Mike



-- 
-------------------
Mike Tancsa, tel +1 519 651 3400 x203
Sentex Communications, mike at sentex.net
Providing Internet services since 1994 www.sentex.net
Cambridge, Ontario Canada   




More information about the freebsd-questions mailing list