ifup / ifdown and /etc/network/interfaces
ifupdown is the classic Debian/Ubuntu network configuration: every interface is described in /etc/network/interfaces, and ifup, ifdown and ifquery read that file and run the ip commands and hook scripts. You still meet it on Debian servers, so knowing its stanzas, methods and hooks matters.
28.1 Where it runs
| Platform | Status |
|---|---|
| Debian / Ubuntu | ifupdown package: /etc/network/interfaces + ifup, ifdown, ifquery |
| Alternatives | ifupdown2, ifupdown-ng (compatible) |
| RHEL / Fedora | Not default: NetworkManager is used |
| Windows / macOS | Does not exist |
28.2 How it works: ifup eth0
- Step 1
1.Read /etc/network/interfaces + sourced interfaces.d/* and find the eth0 stanza
- Step 2
2.Run pre-up hooks in /etc/network/if-pre-up.d/
- Step 3
3.Run ip addr / ip link / ip route for the method (static, dhcp ...)
- Step 4
4.Run up commands and hooks in /etc/network/if-up.d/
- Step 5
5.Save state in /run/network/ifstate (eth0=eth0)
28.3 The interfaces file: stanzas
# /etc/network/interfacessource /etc/network/interfaces.d/*auto loiface lo inet loopback auto eth0iface eth0 inet static address 192.168.48.10/24 gateway 192.168.48.1 up ip route add 10.20.0.0/16 \ via 192.168.48.20 down ip route del 10.20.0.0/16 description Uplink to lab switch iface home inet dhcp hostname srv-home allow-hotplug dummy0iface dummy0 inet static pre-up ip link add dummy0 type dummy address 172.16.48.1/24 iface dummy0 inet6 static address 2001:db8:48::1/64 dad-attempts 0 post-down ip link del dummy0 iface eth0.100 inet static address 10.100.0.5/24| Stanza | Meaning |
|---|---|
| auto IF / allow-auto | Bring up at boot (ifup -a) |
| allow-hotplug IF | Bring up when udev sees the device |
| allow-CLASS IF | Group for ifup --allow=CLASS |
| no-auto-down / no-scripts | Skip on ifdown -a / skip if-*.d hooks |
| rename enp3s0=lan0 | Rename an interface |
| source / source-directory | Include other files / a folder |
| mapping + script + map | Choose a logical interface with a script |
| iface NAME FAMILY METHOD | Define an interface (physical or logical, e.g. home) |
| inherits TEMPLATE | Extend a template stanza |
| iface eth0.100 ... | VLAN id 100 on eth0 |
- Command options valid in any family/method: pre-up, up, post-up, pre-down, down, post-down, description.
- Example: pre-up ip link add dummy0 type dummy creates the device before addressing; post-down deletes it.
28.4 ifquery
- ifquery IF prints the parsed options of a stanza (netmask and broadcast are derived from /24).
- -l lists auto interfaces; -l --allow=hotplug lists a class; --state shows what ifupdown thinks is up.
ifquery eth0ifquery -lifquery -l --allow=hotplugifquery --state$ ifquery eth0address: 192.168.48.10gateway: 192.168.48.1up: ip route add 10.20.0.0/16 via 192.168.48.20down: ip route del 10.20.0.0/16description: Uplink to lab switchbroadcast: 192.168.48.255netmask: 255.255.255.0$ ifquery -lloeth0$ ifquery -l --allow=hotplugdummy0$ ifquery --state; echo exit=$?exit=028.5 ifup: dry run and real run
- ifup -n -v prints the exact commands without running them: always check this first.
- The default route is added with onlink; the up line adds the extra route 10.20.0.0/16.
ifup -n -v eth0$ ifup -n -v eth0ip link set eth0 alias "Uplink to lab switch"ifup: configuring interface eth0=eth0 (inet)run-parts --exit-on-error --verbose /etc/network/if-pre-up.dip addr add 192.168.48.10/255.255.255.0 broadcast 192.168.48.255 dev eth0 label eth0ip link set dev eth0 up ip route add default via 192.168.48.1 dev eth0 onlinkip route add 10.20.0.0/16 via 192.168.48.20run-parts --exit-on-error --verbose /etc/network/if-up.difup -v eth0ip -br addr show eth0ip routeifquery --stateping -c 2 192.168.48.20$ ifup -v eth0ifup: configuring interface eth0=eth0 (inet)ip addr add 192.168.48.10/255.255.255.0 broadcast 192.168.48.255 dev eth0 label eth0ip link set dev eth0 up ip route add default via 192.168.48.1 dev eth0 onlinkip route add 10.20.0.0/16 via 192.168.48.20run-parts: executing /etc/network/if-up.d/myhookrun-parts: executing /etc/network/if-up.d/resolved$ ip -br addr show eth0eth0@if466 UP 192.168.48.10/24$ ip routedefault via 192.168.48.1 dev eth0 onlink10.20.0.0/16 via 192.168.48.20 dev eth0192.168.48.0/24 dev eth0 proto kernel scope link src 192.168.48.10$ ifquery --stateeth0=eth0$ ping -c 2 192.168.48.2064 bytes from 192.168.48.20: icmp_seq=1 ttl=64 time=0.511 ms64 bytes from 192.168.48.20: icmp_seq=2 ttl=64 time=0.136 ms2 packets transmitted, 2 received, 0% packet loss, time 1033ms- Step 1
1.ifup eth0: Debian server gets 192.168.48.10/24
- Step 2
2.Ping to peer 192.168.48.20 crosses the Docker bridge
- Step 3
3.Peer replies through the bridge
- Step 4
4.Default route via gateway 192.168.48.1
- Step 5
5.Ping to 8.8.8.8 goes out through the gateway to the internet
28.6 inet family methods and options
| Method | Meaning | Key options |
|---|---|---|
| loopback | lo, no options | - |
| static | Fixed IPv4 address | address IP/24 (required), gateway, metric, pointopoint, hwaddress, mtu, scope |
| manual | Configure nothing; you add commands | hwaddress, mtu |
| dhcp | dhclient / udhcpc / dhcpcd | hostname, metric, leasetime, vendor, client, hwaddress |
| bootp | Address via BOOTP | bootfile, server, hwaddr |
| tunnel | GRE or IPIP tunnel | mode (required), address, endpoint (required), dstaddr, local, ttl, mtu |
| ppp / wvdial | pon or wvdial dialer | provider, unit, options |
| ipv4ll | 169.254.x.x link-local | - |
- netmask and broadcast are deprecated: use address IP/prefix.
28.7 Logical interfaces: inet dhcp as 'home'
- ifup eth0=home applies the logical stanza 'home' (DHCP) to the physical eth0.
- dhclient broadcasts DISCOVER; the DHCP server on the peer (192.168.48.20) offers 192.168.48.132; ifquery --state shows eth0=home.
ifdown eth0ifup -v eth0=homeip -br addr show eth0ifquery --state$ ifup -v eth0=homeifup: configuring interface eth0=home (inet)DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 3DHCPOFFER of 192.168.48.132 from 192.168.48.20DHCPREQUEST for 192.168.48.132 on eth0 to 255.255.255.255 port 67DHCPACK of 192.168.48.132 from 192.168.48.20bound to 192.168.48.132 -- renewal in 1424 seconds.$ ip -br addr show eth0eth0@if466 UP 192.168.48.132/24$ ifquery --stateeth0=home28.8 inet6, VLAN, ipx and can
| Family / method | Meaning / options |
|---|---|
| inet6 auto | SLAAC (+ stateless DHCPv6 with dhcp 1); privext, accept_ra, request_prefix, ll-attempts |
| inet6 static | Fixed IPv6, SLAAC off; address (required), gateway, dad-attempts 0, preferred-lifetime, scope |
| inet6 dhcp / manual / loopback | Stateful DHCPv6 / nothing / ::1 |
| inet6 tunnel / v4tunnel / 6to4 | ip6gre, ip6ip6, ipip6 / IPv6 over IPv4 / 6to4 |
| ipx static | dynamic | frame 802.2, netnum (legacy IPX) |
| can static | CAN bus: bitrate (required), samplepoint, loopback, listenonly, restart-ms |
- In the lab dummy0 got both inet static and inet6 static stanzas; dad-attempts 0 became 'nodad'.
- iface eth0.100 created an 802.1Q VLAN with id 100 automatically.
ifup -v dummy0ip -br addr show dummy0ifup eth0.100ip -d link show eth0.100 | \ grep -o 'vlan.*id [0-9]*'$ ifup -v dummy0ifup: configuring interface dummy0=dummy0 (inet)ip link add dummy0 type dummyip addr add 172.16.48.1/255.255.255.0 broadcast 172.16.48.255 dev dummy0 label dummy0ip link set dev dummy0 upifup: configuring interface dummy0=dummy0 (inet6)sysctl -q -e -w net.ipv6.conf.dummy0.autoconf=0ip link set dev dummy0 upip -6 addr add 2001:db8:48::1/64 dev dummy0 nodad$ ip -br addr show dummy0dummy0 UNKNOWN 172.16.48.1/24 2001:db8:48::1/64 fe80::cca5:56ff:fe07:9478/64$ ifup eth0.100$ ip -d link show eth0.100 | grep -o 'vlan.*id [0-9]*'vlan protocol 802.1Q id 10028.9 Hook scripts
| Directory / variable | When / meaning |
|---|---|
| if-pre-up.d / if-up.d | Before / after the interface comes up |
| if-down.d / if-post-down.d | Before / after the interface goes down |
| IFACE / LOGICAL | Physical name (eth0) / logical name (home) |
| ADDRFAM / METHOD | inet, inet6, meta / static, dhcp ... |
| MODE / PHASE | start (ifup) or stop (ifdown) / pre-up, post-up, pre-down, post-down |
| CLASS / VERBOSITY | --allow value or auto / 1 with --verbose |
| IF_<OPTION> | Every stanza option, e.g. IF_ADDRESS |
#!/bin/shecho "$PHASE $MODE $IFACE $LOGICAL" \ "$ADDRFAM $METHOD $IF_ADDRESS" \ >> /var/log/ifhook.log install -m 755 /root/myhook \ /etc/network/if-up.d/myhookinstall -m 755 /root/myhook \ /etc/network/if-post-down.d/myhookcat /var/log/ifhook.log$ cat /var/log/ifhook.logpost-up start eth0 eth0 inet static 192.168.48.10post-up start dummy0 dummy0 inet static 172.16.48.1post-up start dummy0 dummy0 inet6 static 2001:db8:48::1post-down stop eth0 eth0 inet static 192.168.48.10post-up start eth0 home inet dhcppost-down stop eth0 home inet dhcppost-up start eth0 eth0 inet static 192.168.48.1028.10 ifup / ifdown options
| Option | Meaning |
|---|---|
| -a, --all | All auto interfaces |
| --allow=CLASS | Only allow-CLASS interfaces |
| -f, --force | Ignore the saved state |
| -n, -v | Dry run, verbose |
| -i FILE, --state-dir=DIR | Other interfaces file, other state dir |
| -o OPTION=VALUE | Set an option as if written in the file (mtu=1400) |
| -X PATTERN | Exclude interfaces |
| --no-scripts / --no-mappings / --ignore-errors | Skip hooks / mapping scripts / continue on errors |
ifup -o mtu=1400 --no-scripts -v eth0ip link show eth0 | head -1ifup -i /root/test.cfg \ --state-dir=/tmp/st test0ls /tmp/st; ip -br link show test0$ ifup -o mtu=1400 --no-scripts -v eth0ifup: configuring interface eth0=eth0 (inet)ip addr add 192.168.48.10/255.255.255.0 broadcast 192.168.48.255 dev eth0 label eth0ip link set dev eth0 mtu 1400 up ip route add default via 192.168.48.1 dev eth0 onlinkip route add 10.20.0.0/16 via 192.168.48.20$ ip link show eth0 | head -19: eth0@if466: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1400 qdisc noqueue state UP mode DEFAULT group default$ cat /root/test.cfgiface test0 inet manual pre-up ip link add test0 type dummy up ip link set test0 up post-down ip link del test0$ ifup -i /root/test.cfg --state-dir=/tmp/st test0$ ls /tmp/st; ip -br link show test0ifstateifstate.test0test0 UNKNOWN 7e:54:f3:9c:ed:0a <BROADCAST,NOARP,UP,LOWER_UP>28.11 Stale state and --force
- If you take a link down with ip link, ifupdown still thinks it is up (ifstate eth0=eth0), so ifup says 'already configured'.
- Fix: ifdown -f eth0; ifup eth0.
ip link set eth0 downifquery --state eth0ifup eth0ifdown -f eth0; ifup eth0ip -br addr show eth0ping -c 1 192.168.48.20 | tail -2$ ip link set eth0 down$ ip -br link show eth0eth0@if466 DOWN ba:c5:75:b5:24:18 <BROADCAST,MULTICAST>$ ifquery --state eth0; echo exit=$?eth0=eth0exit=0$ ifup eth0; echo exit=$?ifup: interface eth0 already configured$ ifdown -f eth0; ifup eth0$ ip -br addr show eth0eth0@if466 UP 192.168.48.10/24$ ping -c 1 192.168.48.20 | tail -21 packets transmitted, 1 received, 0% packet loss, time 0ms28.12 Common mistakes
- Editing the file and expecting it to apply: ifupdown reads it only on ifup; run ifdown IF + ifup IF (check ifup -n -v first).
- Thinking ifdown only removes the IP: it runs down hooks, deletes routes and the address, and takes the link down. Dangerous on a remote SSH interface.
- Mixing ip commands with ifupdown, leaving stale state.
- Using deprecated netmask/broadcast instead of address IP/prefix.
28.13 Interview tips
- ifupdown vs netplan: ifupdown reads /etc/network/interfaces and runs ip commands + hooks directly; netplan generates config from YAML for systemd-networkd or NetworkManager.
- auto = at boot, allow-hotplug = when udev sees the device.
- Logical interfaces: ifup eth0=home applies a different stanza to the same NIC.
- Hooks in if-up.d get IFACE, METHOD, MODE, PHASE and IF_<OPTION> variables.