×


Configuring Static IP and Hostname in FreeBSD 12 Steps to take

Are you trying to configure a Static IP address and hostname in FreeBSD 12?

This guide is for you.


In this context, you are going to see how our Support Experts configured hostname and static IP address on FreeBSD 12.

How to configure Static IP and Hostname in FreeBSD 12?

To begin, you need to make sure that the IP address assigns to an interface and the IP configuration includes in /etc/rc.conf, to have a persistent IP address.
Note that a FreeBSD network interface identifier uses the drive name followed by a number as shown below:

# 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 ) 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>

For instance:
i. Set Server static hostname – freebsd.example.com
ii. Set interface IP Address – 192.168.13.4/24
iii. Change gateway of interface to 192.168.13.1

Provided below are the steps to follow:

1. Configure network settings in FreeBSD
2.Set hostname in FreeBSD 12
3. Set Static IP address in FreeBSD 12
4. Establish a DHCP Address

Now let us look into them in details.


How to Configure network settings in FreeBSD?

Network configurations for FreeBSD are stored in the system configuration file.
The path to this file is "/etc/rc.conf", this is where the server’s host name as well as network interface configurations are set.
Given below is an example for the rc.conf file used by FreeBSD:

hostname=”freebsd12″
ifconfig_em0=”DHCP”
ifconfig_em0_ipv6=”inet6 accept_rtadv”
sshd_enable=”YES”
# Set dumpdev to “AUTO” to enable crash dumps, “NO” to disable
dumpdev=”AUTO”

Here, note the following;
i. The hostname value sets the host name of the FreeBSD server
ii. ifconfig_em0 value sets the network configurations for the em0 network interface
iii. ifconfig_em0_ipv6 value is the IPv6 equvelant of the ifconfig_em0 value
iv. sshd_enable sees whether the SSH daemon is enabled or not.

How to Set Hostname on FreeBSD 12?

To do this, execute;

$ su –
# hostname freebsd.example.com
# echo “\”hostname=freebsd.example.com\”” >> /etc/rc.conf

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

How to Set Static IP Address on FreeBSD 12?

Once we set the hostname, proceed to configure a Static IP address on FreeBSD 12:

# vi /etc/rc.conf

Then Add:

ifconfig_em0=”inet 192.168.13.4 netmask 255.255.255.0″
defaultrouter=”192.168.13.1″

At the end, restart FreeBSD network service and routing table by executing;

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

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

ifconfig_em0="DHCP"

How to go about Setting a DHCP Address?

DHCP address for a network interface on a FreeBSD host is set by editing the system configuration file "/etc/rc.conf".
For instance, to set the network interface em0 to DHCP:

ifconfig_em0="DHCP"

Next, Open the system configuration file into a text editor as shown below;

vi /etc/rc.conf

Then, Update the network interface to use DHCP. In our example, the interface will be em0;

ifconfig_em0="DHCP"

Save the changes and exit the text editor.
Meanwhile, apply new network configurations:

./etc/netstart

Similarly, the system configuration file must resemble with the ifconfig_ interface where we have updated the "DHCP" value.
For instance:

hostname="freebsd12"
ifconfig_em0="DHCP"
ifconfig_em0_ipv6="inet6 accept_rtadv"
sshd_enable="YES"
# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev=”AUTO”


Additionally, to verify if the changes are done successfully, then use the command:

ifconfig em0


[Need additional support to Configure DHCP? We are available to help you today. !]


Conclusion

This article will guide you on how to configure network settings in FreeBSD by setting static IP addresses and DHCP addresses.