SyntaxStudy
Sign Up
Linux / Bash Network Configuration with ip and ifconfig
Linux / Bash Beginner 1 min read

Network Configuration with ip and ifconfig

Linux networking is managed through the kernel networking stack, which is configured and inspected using command-line tools. The modern standard is the `ip` command from the `iproute2` suite, which replaced the older `ifconfig` and `route` commands. However, `ifconfig` is still widely encountered on older systems and in documentation, so familiarity with both is valuable. The `ip addr` command shows all network interfaces and their IP addresses, including IPv4 and IPv6. `ip link` manages interface states and properties. `ip route` shows the routing table, which determines how packets are forwarded. These commands support adding, deleting, and modifying addresses and routes, making them suitable for both inspection and configuration. Persistent network configuration is handled differently across distributions. Ubuntu uses Netplan with YAML configuration files in `/etc/netplan/`. Traditional Debian uses `/etc/network/interfaces`. Red Hat-based systems use NetworkManager or `ifcfg` files in `/etc/sysconfig/network-scripts/`. For most desktop and cloud instances, NetworkManager or `nmcli` is the preferred management tool.
Example
# ---- ip command (modern, preferred) ----

# Show all interfaces and their addresses
ip addr show
ip a              # Shorthand

# Show a specific interface
ip addr show eth0

# Show only IPv4 addresses
ip -4 addr show

# Bring an interface up/down
sudo ip link set eth0 up
sudo ip link set eth0 down

# Add an IP address to an interface
sudo ip addr add 192.168.1.100/24 dev eth0

# Delete an IP address
sudo ip addr del 192.168.1.100/24 dev eth0

# Show routing table
ip route show
ip r              # Shorthand

# Add a default gateway
sudo ip route add default via 192.168.1.1

# Add a specific route
sudo ip route add 10.0.0.0/8 via 192.168.1.254

# Show network statistics
ip -s link show eth0

# ---- ifconfig (legacy) ----
ifconfig                    # Show all interfaces
ifconfig eth0               # Show specific interface
sudo ifconfig eth0 up       # Bring interface up
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0

# ---- DNS resolution ----
cat /etc/resolv.conf        # DNS server configuration
resolvectl status           # systemd-resolved status
nslookup google.com         # Query DNS
dig google.com              # Detailed DNS query
dig +short google.com       # Just the IP
host google.com             # Simple hostname lookup