Interface Configuration
View Interfaces
# List all interfaces
ifconfig
# Specific interface
ifconfig em0
# Just interface names
ifconfig -l
Static IP Configuration
# /etc/rc.conf
ifconfig_em0="inet 192.168.1.100 netmask 255.255.255.0"
defaultrouter="192.168.1.1"
# Apply changes
service netif restart
service routing restart
DHCP Configuration
# /etc/rc.conf
ifconfig_em0="DHCP"
# Apply
service netif restart
Multiple IP Addresses
# /etc/rc.conf
ifconfig_em0="inet 192.168.1.100 netmask 255.255.255.0"
ifconfig_em0_alias0="inet 192.168.1.101 netmask 255.255.255.255"
ifconfig_em0_alias1="inet 192.168.1.102 netmask 255.255.255.255"
DNS Configuration
# /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
search example.com
# Prevent DHCP from overwriting
chflags schg /etc/resolv.conf
Routing
# View routing table
netstat -rn
# Add static route
route add -net 10.0.0.0/8 192.168.1.254
# Persistent routes in /etc/rc.conf
static_routes="internal"
route_internal="-net 10.0.0.0/8 192.168.1.254"
# Delete route
route delete -net 10.0.0.0/8
VLANs
# /etc/rc.conf
vlans_em0="100 200"
ifconfig_em0_100="inet 192.168.100.1 netmask 255.255.255.0"
ifconfig_em0_200="inet 192.168.200.1 netmask 255.255.255.0"
Bridging
# /etc/rc.conf
cloned_interfaces="bridge0"
ifconfig_bridge0="addm em0 addm em1 up"
ifconfig_em0="up"
ifconfig_em1="up"
Wireless Configuration
# /etc/rc.conf
wlans_ath0="wlan0"
ifconfig_wlan0="WPA DHCP"
# /etc/wpa_supplicant.conf
network={
ssid="MyNetwork"
psk="password"
}
Useful Commands
# Show active connections
sockstat -4
# Network statistics
netstat -s
# Check connectivity
ping -c 3 google.com
# DNS lookup
host google.com
drill google.com
# Trace route
traceroute google.com
beginner | Networking | Updated 2025-01-15
- freebsd
- networking
- ifconfig
- routing
- dns