Set hostname & Static IP address on FreeBSD 12/13

Posted on 3 views

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 metric 0 mtu 1500
	options=81009b
	ether 08:00:27:12:6b:98
	inet 10.0.0.11 netmask 0xffffff00 broadcast 10.0.0.255 
	media: Ethernet autoselect (1000baseT )
	status: active
	nd6 options=29
lo0: flags=8049 metric 0 mtu 16384
	options=680003
	inet6 ::1 prefixlen 128 
	inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2 
	inet 127.0.0.1 netmask 0xff000000 
	groups: lo 
	nd6 options=21

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"
coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.