Solved Add IP Address To Cloned Loopback Interface Without Rebooting

reddy

Member

Reaction score: 29
Messages: 63

Hello,

When adding an IP address to a cloned loopback interface in rc.conf (for example lo1) like below:

Code:
ifconfig_lo1_alias1="inet 192.168.185.2/24"
Is it possible to apply the changes without having to reboot the computer? I tried using:

ifconfig lo1 down
ifconfig lo1 up


But ifconfig only started to list the new IP addresses after rebooting the computer.

Thank you
 

scottro

Daemon

Reaction score: 486
Messages: 1,389

Looking at old notes, this used to work, not tested on 12.x

Code:
ifconfig lo1 create
ifconfig lo1 inetn 192.168.185.2/24
And in /etc/rc.conf I have
Code:
cloned_interfaces="lo1"
ipv4_addrs_lo1="192.168.185.2/24"
(That's using the address you have in your post.)

I think I used this page (from 2009)

The /etc/rc.conf stuff definitely still works on FreeBSD-12.x but I don't I created it on the fly with the ifconfig create that I mention above.
 

Bobi B.

Well-Known Member

Reaction score: 142
Messages: 336

One possible way would be to run service netif restart; service routing restart. However it depends on whether you use firewall, VPN servers, with other words, thread carefully, or you might lose remote access to the host.

You might also try service netif start lo1.
 

VladiBG

Aspiring Daemon

Reaction score: 237
Messages: 587

Check if you have lo1 interface
ifconfig lo1

if you don't have lo1 then create it
ifconfig lo1 create
ifconfig lo1 up

to add the primary ip address to the lo1 use
ifconfig lo1 inet 192.168.0.5/24

to add alias (secondary) ip address to the lo1 use
ifconfig lo1 inet 192.168.1.5/24 alias

check the result
ifconfig lo1

to remove the alias ip address from lo1 use
ifconfig lo1 inet 192.168.1.5/24 -alias

to remove the primary ip address from lo use
ifconfig lo1 inet 192.168.0.5/24 delete

to destroy the lo1 interface use
ifconfig lo1 down
ifconfig lo1 destroy

For more commands read the ifconfig(8)
 
OP
OP
reddy

reddy

Member

Reaction score: 29
Messages: 63

scottro Thanks, this is indeed the way I configured it, however my question related to the fact that in order for the changes to be active, you need to be reboot the machine. Edit: sorry, I didn't realize that you used the ifconfig command and not rc.conf when I first read your answer, apologizes.

Bobi B. Many thanks, I will definitely give it a try
 
OP
OP
reddy

reddy

Member

Reaction score: 29
Messages: 63

Check if you have lo1 interface
ifconfig lo1

if you don't have lo1 then create it
ifconfig lo1 create
ifconfig lo1 up

to add the primary address to the lo1 use
ifconfig lo1 inet 192.168.0.5/24

to add alias address to the lo1 use
ifconfig lo1 inet 192.168.1.5/24

check the result
ifconfig lo1

to remove the alias address from lo1 use
ifconfig lo1 inet 192.168.1.5/24 -alias

to remove the primary ip address from lo use
ifconfig lo1 inet 192.168.0.5/24 delete

to destroy the lo1 interface use
ifconfig lo1 down
ifconfig lo1 destroy

For more commands read the ifconfig(8)
Thank you, this is very helpful. So when using the ifconfig command directly, the changes are applied directly without a reboot being required? Also, isn't the alias keyword missing in the command where you create the alias?
 

VladiBG

Aspiring Daemon

Reaction score: 237
Messages: 587

The post was edited i missed alias command at the end.

No reboot required. If you want to make the changes permanent then add them as you do in rc.conf

If you use firewall then you need to reload the firewall service to reflect the creation of the new interface.
 
Top