7.2 Basic Network Management
This section covers the basics of network management and troubleshooting techniques.
Configuring IPv4
Configuring a Dynamic IPv4 Address
If there is a DHCP server on the network, DHCP can be used to dynamically obtain an IP address. FreeBSD uses dhclient(8) as the DHCP client, which can automatically obtain an IP address, subnet mask, and default router.
Note
dhclient(8) does not support DHCPv6 (RFC 3315/RFC 8415). For dynamic IPv6 addresses, use rtsold(8) (SLAAC) or a third-party DHCPv6 client (such as
dhcp6c).
To configure an interface to use DHCP, execute the following command:
# sysrc ifconfig_em0="DHCP"dhclient(8) can also be run manually:
# dhclient em0
DHCPREQUEST on em0 to 255.255.255.255 port 67
DHCPACK from 192.168.1.1
bound to 192.168.1.19 -- renewal in 43200 seconds.dhclient(8) can also be started in the background. Running in the background may affect programs that depend on the network, but in most cases it can speed up the boot process.
To run dhclient(8) in the background, execute the following command:
# sysrc background_dhclient="YES"Then restart the network interface:
Configuring a Static IPv4 Address
Network interfaces can also be configured on the command line using ifconfig(8), but if these configurations are not also written to the /etc/rc.conf file, they will be lost after a reboot.
The IP address can be set using the following command:
To make the changes persistent across reboots, execute the following command:
Set the default route once:
Permanently add a default router:
Add DNS server addresses to the /etc/resolv.conf file:
Then restart the network interface and routing:
ping(8) can be used to test connectivity:
If ICMP response packets are received normally, the network is connected.
Configuring IPv6
IPv6 is the successor protocol to IPv4. IPv6 offers several advantages and new features over IPv4:
Its 128-bit address space can accommodate approximately 3.4×10^38 addresses, thereby solving the IPv4 address shortage and exhaustion problem.
Routers only store network aggregation addresses in their routing tables. Address aggregation reduces the number of routing table entries, which significantly reduces router memory and CPU requirements compared to IPv4.
Address autoconfiguration (RFC 4862).
Replaces broadcast addresses with multicast.
Supports IPsec (IP Security), but it is not mandatory (RFC 6434 has adjusted the requirement for IPv6 nodes to implement IPsec from MUST to SHOULD, making it recommended rather than required).
Simplified header structure.
Support for Mobile IP.
IPv6-to-IPv4 transition mechanisms.
FreeBSD integrates the KAME project's IPv6 reference implementation and includes all components required for IPv6. The KAME project ended in 2006, and its code continues to be maintained and evolved by the FreeBSD project.
IPv6 addresses have three different types:
Unicast
Packets sent to a unicast address arrive at the interface belonging to that address
Anycast
Addresses are syntactically indistinguishable from unicast addresses, but point to a group of interfaces. Packets sent to an anycast address will arrive at the nearest interface
Multicast
An address identifies a group of interfaces. Packets sent to a multicast address will arrive at all interfaces belonging to the multicast group. IPv4 broadcast addresses (typically xxx.xxx.xxx.255) are represented by multicast addresses in IPv6
When reading IPv6 addresses, the canonical form is represented as x:x:x:x:x:x:x:x, where each x represents a 16-bit hexadecimal value. For example, FEBC:A574:382B:23C1:AA49:4592:4EFE:9982.
Consecutive all-zero fields often appear in IPv6 addresses. :: (double colon) can be used to replace a contiguous segment of all-zero fields in an address. Additionally, up to three leading zeros in each hexadecimal value can be omitted. For example, fe80::1 corresponds to the canonical form fe80:0000:0000:0000:0000:0000:0000:0001.
Some IPv6 addresses are reserved:
::/128
Unspecified address
Equivalent to 0.0.0.0 in IPv4
::1/128
Loopback address
Equivalent to 127.0.0.1 in IPv4
::ffff:0.0.0.0/96
IPv4-mapped IPv6 address
The lower 32 bits are the IPv4 address
fe80::/10
Link-local unicast
Equivalent to 169.254.0.0/16 in IPv4
fc00::/7
Unique local
Routable only within a cooperating set of sites
ff00::/8
Multicast
—
2000::/3
Global unicast
All global unicast addresses are allocated from this pool
2001:db8::/32
Documentation use
IPv6 address prefix used in documentation
Configuring a Dynamic IPv6 Address
To dynamically configure an interface's IPv6 address using SLAAC:
Note that when IPv6 packet forwarding is enabled (i.e., ipv6_gateway_enable=YES), the system will not configure SLAAC addresses unless the net.inet6.ip6.rfc6204w3 sysctl(8) variable is set to 1.
Configuring a Static IPv6 Address
To configure a FreeBSD system as an IPv6 client with a static IPv6 address, set the IPv6 address:
To assign a default router:
ping(8) can be used to test connectivity:
If ICMP response packets are received normally, the network is connected.
References
Li Q, Jinmei T, Shima K. IPv6 Core Protocols Implementation (Volume 1)[M]. Translated by Chen Juan, Zhao Zhenping. Beijing: People's Posts and Telecommunications Press, 2009: 846. ISBN: 978-7-115-18950-9 (English reprint edition ISBN: 978-7-115-19551-7). Detailed explanation of IPv6 core protocol implementation, based on FreeBSD KAME project code analysis.
Li Q, Jinmei T, Shima K. IPv6 Advanced Protocols Implementation (Volume 2)[M]. Translated by Wang Jiazhen, et al. Beijing: People's Posts and Telecommunications Press, 2009: 869. ISBN: 978-7-115-20891-0 (English reprint edition ISBN: 978-7-115-19519-7). Detailed explanation of IPv6 advanced protocols and extension mechanisms, including key technologies such as Mobile IPv6.
Network Interface Aliases
One common use of FreeBSD is virtual site hosting, where a single server appears as multiple servers on the network. This is accomplished by assigning multiple network addresses to a single interface.
A network interface can be configured with one primary IP address (Primary Address) and any number of additional IP addresses (Secondary Addresses), which have equal effect in underlying network communication.
Tip
The term "alias" address is merely a traditional naming convention adopted by early operating systems for management convenience; there is no distinction for physical network cards. In fact, IPv6 itself supports multiple addresses.
These aliases are typically implemented by adding alias entries in /etc/rc.conf, as shown below:
Alias entries must start with alias0 and use incrementing numbers, such as alias0, alias1, and so on. The configuration process will stop at the first missing number.
The calculation of alias subnet masks is very important. For a given interface, there must be one address that correctly represents the subnet mask of the network. Any other address belonging to that network must use a subnet mask of all 1s, represented as 255.255.255.255 or 0xffffffff.
For example, consider the following scenario: the em0 interface is connected to two networks:
10.1.1.0, with a subnet mask of 255.255.255.0;
202.0.75.16, with a subnet mask of 255.255.255.240.
We need to configure the system with IP address ranges for two network segments: 10.1.1.1 to 10.1.1.5, and 202.0.75.17 to 202.0.75.20.
Only the first address in a given network range should have the actual subnet mask. The remaining addresses (10.1.1.2 to 10.1.1.5 and 202.0.75.18 to 202.0.75.20) must be configured with a subnet mask of 255.255.255.255.
The following /etc/rc.conf entries configure the interface for this scenario:
A more concise way to express this is to use space-separated IP address ranges. The first address will use the specified subnet mask, while additional addresses will use the subnet mask 255.255.255.255.
Hostname
The hostname represents the Fully Qualified Domain Name (FQDN) of the host on the network.
Check the current hostname:
Temporarily change the hostname:
Change the hostname and make it persistent across reboots:
DNS
DNS can be thought of as a phone book, where IP addresses correspond to hostnames. Unless otherwise specified in the /etc/nsswitch.conf file, FreeBSD will first look up addresses in the /etc/hosts file, then look up DNS information in the /etc/resolv.conf file.
Related file structure:
Local Address hosts File
The /etc/hosts file is a simple text database that provides hostname-to-IP address mapping. Entries for local computers connected via LAN can be added to this file for simple hostname resolution without setting up a DNS server. Additionally, the /etc/hosts file can provide local records for internet domain names, reducing the need to query external DNS servers.
For example, if there is a local instance of www/gitlab-ce in the local environment, the following line can be added to the /etc/hosts file:
Configuring DNS Name Servers
The way FreeBSD systems access the Internet Domain Name System (DNS) is controlled by resolv.conf(5). The most common entries in the /etc/resolv.conf file are:
nameserver
The IP address of the name server that the resolver should query. Servers are queried in the order listed, up to a maximum of three
search
The search list for hostname lookup. Usually determined by the domain of the local hostname
domain
The local domain name
A typical /etc/resolv.conf file looks like this:
The search and domain options are mutually exclusive; if both are specified, only the last one takes effect. When using DHCP, dhclient(8) typically rewrites the /etc/resolv.conf file with information received from the DHCP server.
Since the Dynamic Host Configuration Protocol (DHCP) client rewrites /etc/resolv.conf through the resolvconf service when obtaining network configuration, manually edited configurations may be overwritten upon system reboot.
If you need to use manually configured DNS servers and do not want the system to automatically update and overwrite them, you can disable the resolvconf service. Edit the /etc/resolvconf.conf file (create it if it does not exist) and add the line resolvconf=NO, which will disable the system's automatic updating of DNS configuration files.
References
FreeBSD Project. resolvconf[EB/OL]. [2026-03-26]. https://man.freebsd.org/cgi/man.cgi?query=resolvconf&sektion=8. Man page, providing complete technical documentation for the resolvconf tool, serving as an important reference for DNS configuration management.
FreeBSD Forums. 8.8.8.8 or 1.1.1.1 if set in etc resolv conf doesn't stay as an entry in the file after a network restart[EB/OL]. [2026-03-26]. https://forums.freebsd.org/threads/8-8-8-8-or-1-1-1-1-if-set-in-etc-resolv-conf-doesnt-stay-as-an-entry-in-the-file-after-a-network-restart.85951/. Practical case analysis, providing solutions to prevent DNS configuration from being overwritten.
Network Troubleshooting
First, check the following basic elements:
Is the power connection normal?
Is the router working properly?
Have the broadband or network fees been paid?
Is there a regional large-scale network outage?
Is the computer's time correct?
Is the network cable connected properly?
Is the network service correctly configured?
Is the firewall correctly configured?
Is the network card supported by FreeBSD?
If the network card is working but performance is poor, refer to tuning(7). Incorrect network settings can cause slow connections; network configuration should also be checked.
The "No route to host" message indicates that the system cannot route packets to the destination host. This is usually because no default route has been specified or the network cable is not connected. Use the route get <destination_address> command to view the system's routing decision for a specific destination, then check the output of netstat -rn to ensure there is a valid route to the host.
The error message ping: sendto: Permission denied is usually caused by a firewall configuration error. If the IPFW firewall module is loaded directly without any rules configured, IPFW's default rule 65535 denies all traffic, even ping(8).
When enabling the firewall via rc.conf:
The default value of
firewall_typeis"UNKNOWN", in which case no allow rules are added, and only the default rule 65535 (deny all) takes effectIf
firewall_typeis explicitly set to"open", IPFW will add an allow rule at rule 65000, overriding the default deny behavior.
PF and IPFilter default to allowing traffic when no rules are present.
Viewing Network Card Speed
To monitor network interface traffic statistics in real time, use the systat tool's network interface view. This command displays receive and transmit traffic data for each network interface at a specified refresh interval:
The -ifstat parameter specifies displaying network interface information, and the number 2 indicates a refresh interval of 2 seconds.
Viewing FreeBSD Download Traffic (bwm-ng)
To view more detailed network traffic statistics, install the bwm-ng tool, which provides multiple traffic display formats and interactive features:
Press the letter d to switch traffic display formats, and press h for more usage information.
Appendix: /etc/rc.conf Network Configuration Examples
Note:
After modifying the /etc/rc.conf file, you need to restart the system or run the commands
service netif restartandservice routing restartin sequence to apply the network changes.
Hostname (must not be empty, otherwise Xorg cannot be used):
Dynamic DHCP Method
Dynamic DHCP method: configure network card igc0 to use DHCP:
Static IP Method
Static IP method: set the IPv4 address of network card igc0 to 192.168.5.77, with a subnet mask of 255.255.255.0:
Default gateway/default route, typically the router's IP address:
Set an alias IPv4 address 192.168.5.12 for network card igc0, with a subnet mask of 255.255.255.255 (when on the same subnet as the primary address, an all-1s mask must be used) to obtain an additional IPv4 address:
Note:
If the alias address is on the same subnet as the primary address, the subnet mask must be set to 255.255.255.255 (0xffffffff), otherwise a duplicate route error will occur. Aliases on different subnets use the normal subnet mask for that subnet.
Static routes:
① In the /etc/rc.conf file, if you need to write multiple configuration items at once, you must use the format ABC_XYZ="xxx yyy ccc ddd". Writing it in the following form is incorrect:
Because in this form, subsequent ABC_XYZ configuration lines will overwrite the previous line, so only the last line will take effect.
Example: To access the 192.168.50.0/24 address block (usable host IPs from 192.168.50.1 to 192.168.50.254), send packets to 192.168.1.1 for forwarding:
Example: To access the 10.88.200.0/24 address block (usable host IPs from 10.88.200.1 to 10.88.200.254), send packets to 10.10.10.254 for forwarding:
Exercises
Configure dual static IP addresses on a FreeBSD system, set different DNS servers for each, use the
digcommand to verify the resolution behavior of each DNS server, and analyze the query order and fault tolerance mechanism of multiple DNS server entries in /etc/resolv.conf.Modify the MTU (Maximum Transmission Unit) value of a network interface to 9000 (jumbo frames), use
pingto test connectivity, record the impact of MTU changes on large packet transmission, and analyze the applicable scenarios of jumbo frames in local area networks and wide area networks.Disable the
resolvconfservice, manually modify the /etc/resolv.conf file and restart the network service, verify whether the configuration is persistent, and analyze the mechanism ofresolvconffor dynamic management of DNS configuration.
Last updated