Thursday, September 4, 2025
HomeGuest BlogsSet hostname & Static IP address on FreeBSD 12/13

Set hostname & Static IP address on FreeBSD 12/13

So you’re trying to learn how to set a hostname & static IP address on FreeBSD 12/13?. In this guide I’ll show you how easy it is to a hostname and a Static IP address on FreeBSD 12/13.  Please note that the FreeBSD network interface identifier uses the driver name followed by a number.

# ifconfig
em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
	options=81009b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,VLAN_HWFILTER>
	ether 08:00:27:12:6b:98
	inet 10.0.0.11 netmask 0xffffff00 broadcast 10.0.0.255 
	media: Ethernet autoselect (1000baseT <full-duplex>)
	status: active
	nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
	options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
	inet6 ::1 prefixlen 128 
	inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2 
	inet 127.0.0.1 netmask 0xff000000 
	groups: lo 
	nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>

To have a persistent IP address on your FreeBSD 12/13 server, the IP address must be assigned to an interface and the IP configuration included in /etc/rc.conf. Let’s consider an example below:

  • Set Server static hostname – freebsd.example.com
  • Set interface IP Address – 192.168.13.4/24
  • Set gateway for interface to 192.168.13.1

Set Hostname on FreeBSD 12 / FreeBSD 13

Set a hostname on FreeBSD 12/13 using the commands below:

$ sudo hostname freebsd.example.com
$ sudo vim /etc/rc.conf
hostname=freebsd.example.com

If the dhclient is used to set the hostname via DHCP, the hostname variable should be set to an empty string

Set Static IP Address on FreeBSD 12 / FreeBSD 13

Now that you have the hostname set, proceed to configure a Static IP address on FreeBSD.

sudo vim /etc/rc.conf

Add:

ifconfig_em0="inet 192.168.13.4 netmask 255.255.255.0"
defaultrouter="192.168.13.1"

Restart FreeBSD network service and routing table:

sudo /etc/rc.d/netif restart && sudo /etc/rc.d/routing restart

To configure an interface for DHCP, reset the settings to:

ifconfig_em0="DHCP"

RELATED ARTICLES

Most Popular

Dominic
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS