Don’t know how to set a Static IP address and hostname in FreeBSD 12? We can help you.
Today, we are going to see how our Support Engineers set hostname and static IP address on FreeBSD 12.
Set Static IP and Hostname in FreeBSD 12
Initially, we 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.
Please keep in mind 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 example:
- Set Server static hostname – freebsd.example.com
- Set interface IP Address – 192.168.13.4/24
- Change gateway of interface to 192.168.13.1
Given below are the steps to follow:
- Configure network settings in FreeBSD
- Set hostname in FreeBSD 12
- Set Static IP address in FreeBSD 12
- Establish a DHCP Address
Let us now look into it in detail.
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”
- The hostname value sets the host name of the FreeBSD server
- ifconfig_em0 value sets the network configurations for the em0 network interface
- ifconfig_em0_ipv6 value is the IPv6 equvelant of the ifconfig_em0 value
- sshd_enable sees whether the SSH daemon is enabled or not.
Set Hostname on FreeBSD 12
$ 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.
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
Add:
ifconfig_em0=”inet 192.168.13.4 netmask 255.255.255.0″
defaultrouter=”192.168.13.1″
Later, restart FreeBSD network service and routing table:
# /etc/rc.d/netif restart && /etc/rc.d/routing restart
Simultaneously, to configure an interface for DHCP, reset the settings to:
ifconfig_em0=”DHCP”
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”
- Open the system configuration file into a text editor
vi /etc/rc.conf
- 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”
Furthermore, to verify if the changes are done successfully use the command:
ifconfig em0
[Need further assistance? We are here for you!]
Conclusion
To conclude, today, we saw how our Support Engineers configure network settings in FreeBSD by setting static IP addresses and DHCP addresses.
0 Comments