Introduction
FreeBSD offers powerful and flexible networking capabilities. This guide will walk you through the process of configuring various aspects of networking on a FreeBSD system, from basic interface setup to advanced features.
1. Basic Network Interface Configuration
1.1 Identifying Network Interfaces
To list all network interfaces on your system:
ifconfig -a
1.2 Configuring Network Interfaces
Edit /etc/rc.conf to configure network interfaces. For example, to configure em0 with a static IP:
ifconfig_em0="inet 192.168.1.100 netmask 255.255.255.0"
defaultrouter="192.168.1.1"
For DHCP configuration:
ifconfig_em0="DHCP"
1.3 Applying Network Configuration
After editing rc.conf, restart networking with:
service netif restart && service routing restart
2. DNS Configuration
2.1 Configuring DNS Servers
Edit /etc/resolv.conf to set DNS servers:
nameserver 8.8.8.8
nameserver 8.8.4.4
2.2 Setting Hostname
Set your system's hostname in /etc/rc.conf:
hostname="myhostname.mydomain.com"
3. Wireless Networking
3.1 Loading Wireless Drivers
Add the following to /boot/loader.conf to load wireless drivers at boot:
if_iwm_load="YES"
iwm8265fw_load="YES"
3.2 Configuring Wireless Interface
Add the following to /etc/rc.conf:
wlans_iwm0="wlan0"
ifconfig_wlan0="WPA SYNCDHCP"
3.3 Setting Up WPA
Create and edit /etc/wpa_supplicant.conf:
network={
ssid="your_ssid"
psk="your_password"
}
4. Network Address Translation (NAT)
4.1 Enabling Packet Forwarding
Add to /etc/rc.conf:
gateway_enable="YES"
4.2 Configuring NAT with PF
Add to /etc/pf.conf:
nat on $ext_if from $int_if:network to any -> ($ext_if)
Where $ext_if is your external interface and $int_if is your internal interface.
5. VLAN Configuration
5.1 Creating VLAN Interface
Add to /etc/rc.conf:
vlans_em0="10 20"
ifconfig_em0.10="inet 192.168.10.1 netmask 255.255.255.0"
ifconfig_em0.20="inet 192.168.20.1 netmask 255.255.255.0"
6. Firewall Configuration
6.1 Enabling PF Firewall
Add to /etc/rc.conf:
pf_enable="YES"
6.2 Basic PF Configuration
Edit /etc/pf.conf with basic rules:
ext_if="em0"
block in all
pass out all keep state
pass in on $ext_if proto tcp to port 22
7. IPv6 Configuration
7.1 Enabling IPv6
Add to /etc/rc.conf:
ipv6_activate_all_interfaces="YES"
ifconfig_em0_ipv6="inet6 accept_rtadv"
7.2 Static IPv6 Address
For a static IPv6 address, use:
ifconfig_em0_ipv6="inet6 2001:db8::2 prefixlen 64"
ipv6_defaultrouter="fe80::1%em0"
8. Network Tuning
8.1 Increasing Network Performance
Add to /etc/sysctl.conf:
net.inet.tcp.sendspace=65536
net.inet.tcp.recvspace=65536
kern.ipc.maxsockbuf=2097152
Tip: Always test thoroughly after making network configuration changes, especially in production environments.