Setting up NetBSD networking: configuring interfaces with ifconfig, routing, and /etc/resolv.conf, as well as understanding advanced features like interface aliases, VLAN, bonding (lagg), and bridges.

In episode 7 we understood filesystems and disks — where NetBSD data rests. But a server is meaningless without connectivity. In this episode we'll connect the system to the outside world: networking and network configuration on NetBSD — configuring interfaces with ifconfig, building routes with route, setting up the resolver with /etc/resolv.conf, and exploring advanced features like interface aliases, VLAN, bonding, and bridges.
ifconfig -awm0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
address: 52:54:00:12:34:56
inet 192.168.1.50 netmask 0xffffff00 broadcast 192.168.1.255
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33624
inet 127.0.0.1 netmask 0xff000000NetBSD interface names follow a pattern: wm0 for Intel PRO/1000, re0 for Realtek, virtio0 for KVM/QEMU VMs, and lo0 for loopback. For a concise list of all active interfaces:
ifconfig -llo0 wm0Permanent interface configuration is written in /etc/rc.conf — remember the pattern from episode 6. Here are the two most common scenarios:
hostname="nbsd11"
ifconfig_wm0="inet 192.168.1.50 netmask 255.255.255.0"
defaultroute="192.168.1.1"ifconfig_wm0="DHCP"Changes to rc.conf only take effect at boot. To apply them immediately without rebooting, use ifconfig on the command line:
ifconfig wm0 inet 192.168.1.50 netmask 255.255.255.0ifconfig wm0 upTo reset to DHCP:
dhcpcd wm0Warning
ifconfig changes on the command line are lost at reboot. If you want them permanent, always write them in /etc/rc.conf. Rule of thumb: live for testing, rc.conf for permanent.
route showRouting tables
Internet:
Destination Gateway Flags Use Mtu Interface
default 192.168.1.1 UGS 12 - wm0
loopback localhost UH - 33624 lo0
192.168.1.0/24 link#1 U 5 - wm0Adding a static route manually:
route add 10.10.10.0/24 192.168.1.254Removing a route:
route delete 10.10.10.0/24To enable forwarding (so NetBSD acts as a router), set a sysctl:
sysctl -w net.inet.ip.forwarding=1Name resolution is configured in /etc/resolv.conf:
nameserver 8.8.8.8
nameserver 1.1.1.1
domain example.comTest name resolution with nslookup or dig:
nslookup netbsd.orgServer: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: netbsd.org
Address: 156.146.41.125A single physical interface can hold multiple IPs:
ifconfig wm0 alias 192.168.1.51ifconfig wm0For permanence, write it in rc.conf as two lines:
ifconfig_wm0="inet 192.168.1.50 netmask 255.255.255.0"
ifconfig_wm0_alias0="inet 192.168.1.51 netmask 255.255.255.255"VLANs split one physical network into multiple logical networks (802.1Q). First make sure VLAN support exists, then create a VLAN interface:
ifconfig vlan0 create
ifconfig vlan0 vlan 10 vlanif wm0
ifconfig vlan0 inet 10.0.10.1/24lagg combines multiple interfaces for redundancy or bandwidth. Creating a lagg with two ports:
ifconfig lagg0 create
ifconfig lagg0 laggproto failover laggport wm0 laggport re0
ifconfig lagg0 inet 192.168.1.60/24 upA bridge connects multiple interfaces at layer 2 — the basis of a virtual switch:
ifconfig bridge0 create
ifconfig bridge0 add wm0 add re0
ifconfig bridge0 upWhen networking is broken, follow a systematic approach:
| Step | Command | What to Check |
|---|---|---|
| 1 | ifconfig -a | Does the interface exist and is it UP? |
| 2 | route show | Does the default route exist? |
| 3 | ping 192.168.1.1 | Is the gateway reachable? |
| 4 | nslookup netbsd.org | Does DNS work? |
| 5 | ping netbsd.org | Is the internet reachable? |
ping -c 3 8.8.8.8In this episode 8, you've mastered NetBSD networking: finding and configuring interfaces with ifconfig, static IP and DHCP configuration in /etc/rc.conf, routing with route, DNS resolution with /etc/resolv.conf, and advanced features like aliases, VLAN, bonding (lagg), and bridges.
Key takeaways:
/etc/rc.conf; live ifconfig changes vanish on reboot.ifconfig_wm0="inet 192.168.1.50 netmask 255.255.255.0" + defaultroute./etc/resolv.conf; test with nslookup.In the next episode, episode 9, we'll go deeper into the machine: kernel modules and kernel configuration — loading modules with modload, assembling your own kernel with config, and building the kernel with build.sh. See you in episode 9!