SkillPilotAI

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

PlatformStatus
Debian / Ubuntuifupdown package: /etc/network/interfaces + ifup, ifdown, ifquery
Alternativesifupdown2, ifupdown-ng (compatible)
RHEL / FedoraNot default: NetworkManager is used
Windows / macOSDoes not exist

28.2 How it works: ifup eth0

What happens on sudo ifup eth0
  1. 1.Read /etc/network/interfaces + sourced interfaces.d/* and find the eth0 stanza

  2. 2.Run pre-up hooks in /etc/network/if-pre-up.d/

  3. 3.Run ip addr / ip link / ip route for the method (static, dhcp ...)

  4. 4.Run up commands and hooks in /etc/network/if-up.d/

  5. 5.Save state in /run/network/ifstate (eth0=eth0)

28.3 The interfaces file: stanzas

Output
# /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
StanzaMeaning
auto IF / allow-autoBring up at boot (ifup -a)
allow-hotplug IFBring up when udev sees the device
allow-CLASS IFGroup for ifup --allow=CLASS
no-auto-down / no-scriptsSkip on ifdown -a / skip if-*.d hooks
rename enp3s0=lan0Rename an interface
source / source-directoryInclude other files / a folder
mapping + script + mapChoose a logical interface with a script
iface NAME FAMILY METHODDefine an interface (physical or logical, e.g. home)
inherits TEMPLATEExtend 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.
Terminal
ifquery eth0ifquery -lifquery -l --allow=hotplugifquery --state
Output
$ 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=0

28.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.
Terminal
ifup -n -v eth0
Output
$ 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.d
Terminal
ifup -v eth0ip -br addr show eth0ip routeifquery --stateping -c 2 192.168.48.20
Output
$ 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
inet static: eth0 in the lab
  1. 1.ifup eth0: Debian server gets 192.168.48.10/24

  2. 2.Ping to peer 192.168.48.20 crosses the Docker bridge

  3. 3.Peer replies through the bridge

  4. 4.Default route via gateway 192.168.48.1

  5. 5.Ping to 8.8.8.8 goes out through the gateway to the internet

28.6 inet family methods and options

MethodMeaningKey options
loopbacklo, no options-
staticFixed IPv4 addressaddress IP/24 (required), gateway, metric, pointopoint, hwaddress, mtu, scope
manualConfigure nothing; you add commandshwaddress, mtu
dhcpdhclient / udhcpc / dhcpcdhostname, metric, leasetime, vendor, client, hwaddress
bootpAddress via BOOTPbootfile, server, hwaddr
tunnelGRE or IPIP tunnelmode (required), address, endpoint (required), dstaddr, local, ttl, mtu
ppp / wvdialpon or wvdial dialerprovider, unit, options
ipv4ll169.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.
Terminal
ifdown eth0ifup -v eth0=homeip -br addr show eth0ifquery --state
Output
$ 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=home

28.8 inet6, VLAN, ipx and can

Family / methodMeaning / options
inet6 autoSLAAC (+ stateless DHCPv6 with dhcp 1); privext, accept_ra, request_prefix, ll-attempts
inet6 staticFixed IPv6, SLAAC off; address (required), gateway, dad-attempts 0, preferred-lifetime, scope
inet6 dhcp / manual / loopbackStateful DHCPv6 / nothing / ::1
inet6 tunnel / v4tunnel / 6to4ip6gre, ip6ip6, ipip6 / IPv6 over IPv4 / 6to4
ipx static | dynamicframe 802.2, netnum (legacy IPX)
can staticCAN 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.
Terminal
ifup -v dummy0ip -br addr show dummy0ifup eth0.100ip -d link show eth0.100 | \  grep -o 'vlan.*id [0-9]*'
Output
$ 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 100

28.9 Hook scripts

Directory / variableWhen / meaning
if-pre-up.d / if-up.dBefore / after the interface comes up
if-down.d / if-post-down.dBefore / after the interface goes down
IFACE / LOGICALPhysical name (eth0) / logical name (home)
ADDRFAM / METHODinet, inet6, meta / static, dhcp ...
MODE / PHASEstart (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
Terminal
#!/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
Output
$ 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.10

28.10 ifup / ifdown options

OptionMeaning
-a, --allAll auto interfaces
--allow=CLASSOnly allow-CLASS interfaces
-f, --forceIgnore the saved state
-n, -vDry run, verbose
-i FILE, --state-dir=DIROther interfaces file, other state dir
-o OPTION=VALUESet an option as if written in the file (mtu=1400)
-X PATTERNExclude interfaces
--no-scripts / --no-mappings / --ignore-errorsSkip hooks / mapping scripts / continue on errors
Terminal
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
Output
$ 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.
Terminal
ip link set eth0 downifquery --state eth0ifup eth0ifdown -f eth0; ifup eth0ip -br addr show eth0ping -c 1 192.168.48.20 | tail -2
Output
$ 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 0ms

28.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.