[How To] set or change the IP address on FreeBSD
|Changing the IP address of a FreeBSD system is relatively easy and can be done with a few simple commands. The process involves using the ifconfig command pattern to assign the desired IP address and subnet mask to the desired interface. To make the changes permanent, you will also need to make changes to the configuration files in /etc/rc.conf or /etc/rc.conf.d/. In this article, we will explain how to set or change the IP address on a FreeBSD system.
Table of Contents
Basic Syntax
To change the IP address of an interface, use the following command pattern:
sudo ifconfig interface_name inet new_ip_address netmask subnet_mask
Example
Let’s say you have an interface called em0 which you want to change the IP address for. To do this, you would follow the steps below:
-
To change the IP address of the em0 interface to 192.168.1.100 with a subnet mask of 255.255.255.0, you would use the following command:
sudo ifconfig em0 inet 192.168.1.100 netmask 255.255.255.0
-
To make the changes permanent, you will need to edit the configuration files in /etc/rc.conf or /etc/rc.conf.d/
sudo vi /etc/rc.conf
-
Edit the line that starts with “ifconfig_em0” and add the IP, netmask and any other options you need.
ifconfig_em0="inet 192.168.1.100 netmask 255.255.255.0"
-
After that, you need to restart the network service or reboot your computer.
sudo service netif restart
The above steps and commands are just an example, the actual commands and filenames may vary depending on your system configuration. It is also important to note that you can use the same command pattern to set or change the IP address for any interface on your FreeBSD system.
Conclusion
In this article, we have explained how to set or change the IP address on a FreeBSD system. We have also provided an example of how to do this for the em0 interface. Remember that the actual commands and filenames may vary depending on your system configuration.
FreeBSDs’ ifconfig supports CIDR notation and has inet as default for address family, so you can write:
doas ifconfig em0 192.168.1.10/24
ifconfig_em0=”192.168.1.100/24″