How to set hostname and static IP address on FreeBSD 12

So you are trying to learn how to set a host name and a static IP address on FreeBSD 12? In this guide, I will show you how easy hostnames and static IP addresses are on FreeBSD 12. Please note that FreeBSD network interface identifier uses driver name With one 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 permanent IP address on your FreeBSD 12 server, you must assign that IP address to an interface, and the IP configuration is included in it. /etc/rc.conf. Let us consider the following example:

  • Set server static hostname – freebsd.example.com
  • Set Interface IP Address – 192.168.13.4/24
  • Set the interface to 192.168.13.1

Setting the hostname on FreeBSD 12

Set the hostname on FreeBSD 12 using the following command:

$ su -
# hostname freebsd.example.com
# echo ""hostname=freebsd.example.com"" >>  /etc/rc.conf

in case dhclient Used to set the host name via DHCP, the host name variable should be set to an empty string

Setting a static IP address on FreeBSD 12

Now that the hostname is set, continue to configure a static IP address on FreeBSD 12.

# vi /etc/rc.conf

plus:

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

Restart FreeBSD network services and routing tables:

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

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

ifconfig_em0="DHCP"
Sidebar