This article is an article where the title itself is titled as ‘How to Set Network Interface for DHCP in FreeBSD’ clearly discuss on how to configure a network interface detected in FreeBSD operating system can be initialized with a proper IP Address via DHCP method. There is two network interfaces detected where it actually network interfaces simulated in VirtualBox. The first one, the ’em0′ network interface is connected in to a NAT adapter. The second one, the ’em1′ is connected to the Host-only Adapter. So, the following is the output of the network interface listed after executing the command ‘/sbin/ifconfig’ :
root@mybsd:~ # /sbin/ifconfig em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 options=9b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM> ether 08:00:27:5d:dc:96 hwaddr 08:00:27:5d:dc:96 inet 10.0.2.15 netmask 0xffffff00 broadcast 10.0.2.255 nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL> media: Ethernet autoselect (1000baseT <full-duplex>) status: active em1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 options=9b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM> ether 08:00:27:5f:b7:29 hwaddr 08:00:27:5f:b7:29 nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL> media: Ethernet autoselect (1000baseT <full-duplex>) status: active lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384 options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6> inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3 inet 127.0.0.1 netmask 0xff000000 nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL> groups: lo root@mybsd:~ #
As shown in the above output generated which is basically executing ‘/sbin/ifconfig’, there is no IP Address attached to the second network interface called ’em1′. So, in order to set an IP Address using DHCP method, the following is the steps taken to achieve it :
1. As root account, edit the following configuration located in ‘/etc/rc.conf’. Add the following line of configuration as follows :
ifconfig_em1 = "DHCP"
2. Restart the network service by executing the following command :
/sbin/ifconfig network_interface_name up
The above command is executed in the real situation where it can be shown in the following command, the network interface name is ’em1′ :
/sbin/ifconfig em1 up
Or it can be done by executing the following command :
service netif restart
For restarting service in network, further reading can be found in the article titled ‘How to Restart Network Service in FreeBSD’ in this link . The above command will restart the network service which is in the end it will re-initialize all of the network interface available in the operating system. So, after the network restart process, the following output will be generated by executing the command ‘/sbin/ifconfig’ :
root@mybsd:~ # /sbin/ifconfig em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 options=9b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM> ether 08:00:27:5d:dc:96 hwaddr 08:00:27:5d:dc:96 inet 10.0.2.15 netmask 0xffffff00 broadcast 10.0.2.255 nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL> media: Ethernet autoselect (1000baseT <full-duplex>) status: active em1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 options=9b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM> ether 08:00:27:5f:b7:29 hwaddr 08:00:27:5f:b7:29 inet 192.168.56.3 netmask 0xffffff00 broadcast 192.168.56.255 nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL> media: Ethernet autoselect (1000baseT <full-duplex>) status: active lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384 options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6> inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3 inet 127.0.0.1 netmask 0xff000000 nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL> groups: lo root@mybsd:~ #
As shown in the above output, the interface named ’em1′ has already been initialized with an IP Address of ‘192.168.56.3’.