Set Static IP Address in FreeBSD

Before you begin, find out what is the interface name using the ifconfig command.

$ ifconfig -a
em0: flags=8843 metric 0 mtu 1500 options=209b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_MAGIC>
ether 7a:98:a6:53:cd:7a
hwaddr 7a:98:a6:53:cd:7a
inet 192.168.0.103 netmask 0xffffff00 broadcast 192.168.0.255
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
media: Ethernet autoselect (1000baseT <full-duplex>)
status: active
lo0: flags=8049 metric 0 mtu 16384
options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2
inet 127.0.0.1 netmask 0xff000000
nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
groups: lo

In this case the interface name is em0.

a. set temporary static IP (until next reboot)

# set temporary IP address to 192.168.0.103
$ ipconfig em0 inet 192.168.0.103

b. set permanent static IP address (persistent across reboots)

Static IP configuration must be included in /etc/rc.conf. Edit rc.conf using your favorite editor.

Delete or comment out the following line

#ifconfig_em0="DHCP"

Add the following lines after hostname directive:

ifconfig_em0="inet 192.168.0.103 netmask 255.255.255.0"
defaultrouter="192.168.0.1"

Restart network interface service

$ sudo service netif restart 

Note:

Be aware that this method of setting a static IP address in rc.conf will disable the DHCP server. If you have custom DNS servers defined in /etc/dhclient.conf, they will not work. In this case, the custom DNS servers must be added in the /etc/resolv.conf file.