Inspect and Safely Adjust Linux Interfaces with ifconfig
ifconfig shows you which interfaces exist, which one just dropped, and the shape of a narrowly scoped change before you make it. The command is part of the legacy net-tools package; this machine has net-tools 2.10-0.1ubuntu4.4 installed.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about fifteen minutes. You need a shell; inspection is normally unprivileged. Configuration changes usually need root and can interrupt networking, so line up a console or an out-of-band recovery path before touching the interface carrying your current connection.
1. List interfaces you can see
Start with the read-only form. With no arguments, ifconfig shows active interfaces. Add -a to include interfaces that are currently down:
$ ifconfig -a
br-example: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.0.2.10 netmask 255.255.255.0 broadcast 192.0.2.255
ether 02:00:00:00:00:10 txqueuelen 0 (Ethernet)
The names, addresses and counters are host-specific. What matters is the interface name, flags, MTU, protocol addresses, hardware address and packet counters; the exact flags are also driver-dependent. Do not copy an address or MAC address from this sample into a real configuration.
Checkpoint
Record the exact interface name you intend to inspect. A name such as enp0s31f6, eth0 or br-example is not interchangeable with another device.
2. Inspect one interface
Pass one interface name to see only that device:
$ ifconfig INTERFACE_NAME
INTERFACE_NAME: flags=... mtu 1500
inet ADDRESS netmask NETMASK broadcast BROADCAST
Swap INTERFACE_NAME for a name from ifconfig -a. Get it wrong and the command reports an error rather than showing another interface. Use -v when that error is not clear enough:
$ ifconfig -v INTERFACE_NAME
Use -s for a short list similar to netstat -i. None of these inspection commands change addresses, flags or link state.
3. Read the address and mask together
For IPv4, the inet line carries the address and netmask. The mask decides which addresses count as local to that interface. The manpage says that if you set an address without a mask, ifconfig derives a usual class A, B or C mask from the address; that is an old default, not a substitute for checking the actual network design. Supply the intended mask explicitly when configuring an interface.
IPv6 addresses appear on inet6 lines with a prefix length. The address family defaults to IPv4; use inet6 when the operation needs IPv6 syntax. The manpage's form for adding an IPv6 address looks like this:
$ sudo ifconfig INTERFACE_NAME inet6 add 2001:db8:1234::10/64
This changes live kernel state and can affect routing or reachability. Do not run it with an address copied straight from documentation. Swap in an address and prefix actually assigned to this host, and check the result immediately:
$ ifconfig INTERFACE_NAME
INTERFACE_NAME: flags=... mtu 1500
inet6 2001:db8:1234::10 prefixlen 64 scopeid 0x0<global>
To remove the address added above, use the matching address and prefix:
$ sudo ifconfig INTERFACE_NAME inet6 del 2001:db8:1234::10/64
Warning
That undo command is only correct for an address you deliberately added yourself. Removing an existing service address can disconnect applications.
4. Make a small IPv4 change only with a recovery path
The general IPv4 configuration shape is:
$ sudo ifconfig INTERFACE_NAME 192.0.2.10 netmask 255.255.255.0
Assigning an address implicitly activates the interface unless you use the special alias behaviour the manpage describes. The command does not make the setting persistent across a reboot: distribution network management, whether a service or a configuration file, may later reapply its own state on top.
Before you press Enter, check three things: the interface name, the address ownership, and the netmask. This is a service-disrupting action, so keep a second session open if you can. Once it returns, inspect the interface:
$ ifconfig INTERFACE_NAME
INTERFACE_NAME: flags=... mtu 1500
inet 192.0.2.10 netmask 255.255.255.0
There is no universal undo value here. Restore the address and mask you had recorded from your earlier output, or let the host's network manager reapply its own configuration. Do not guess an old address from memory.
5. Understand link flags and MTU changes
up activates an interface and down shuts its driver down. Both can break traffic immediately; a reversible-looking command is still disruptive:
$ sudo ifconfig INTERFACE_NAME down
$ sudo ifconfig INTERFACE_NAME up
Only run this once you have confirmed the interface and have a recovery route. The mtu option changes the maximum transfer unit:
$ sudo ifconfig INTERFACE_NAME mtu 1400
$ ifconfig INTERFACE_NAME
Restore the previous MTU from your recorded output; commonly 1500, but not always. An MTU mismatch can cause fragmentation or failed connections, so test the affected traffic rather than trusting a successful command exit alone.
6. Avoid the traps that cause the most damage
- Do not run
ifconfigwith no interface when you meant to inspect a particular device. No arguments only reports active interfaces. - Do not assume
-ameans every possible device. It reports interfaces currently available to the command, including those that are down. - Do not enable
promiscorallmultias a diagnostic guess. They change which packets the interface receives, and can widen your capture or processing exposure. - Do not change a hardware address with
hwunless the driver supports it and you understand the effect on switching, leases and access controls. - Do not treat a successful address change as persistent. Check whichever network manager or distribution configuration actually owns the interface.
For newer Linux systems, the manpage points to ip link from the iproute2 package for complete link-layer information, in particular because this old ioctl interface cannot display all 20 bytes of an Infiniband hardware address correctly. That is a limitation of this command, not evidence that the address is actually short.
Done means
- Interface named exactly. You used
ifconfig -ato find the exact interface name. - State recorded. You inspected the selected interface and recorded its address, mask, MTU and flags.
- IPv4 and IPv6 kept separate. You treated the two as separate syntaxes, not interchangeable options.
- Every change reversible. Every live change had an explicit elevated command, a verification step and a recovery value.
- Persistence understood. You know which persistent network configuration will reapply the desired state after reboot.