How to Set Up and Use `ip` and `ifconfig` Commands in Debian 12 Bookworm
ip and ifconfig commands in Debian 12 Bookworm.Categories:
4 minute read
Introduction
In Debian 12 Bookworm, managing network interfaces efficiently is crucial for both system administrators and general users. Debian has transitioned from older network utilities like ifconfig to the more modern ip command from the iproute2 package. However, ifconfig is still available through the net-tools package for those who prefer the traditional method.
This guide will walk you through installing, setting up, and using both ip and ifconfig commands on Debian 12.
1. Installing Required Packages
Checking Installed Network Tools
By default, Debian 12 comes with iproute2, which provides the ip command, but ifconfig may not be available by default. You can check their availability with:
which ip
which ifconfig
If ifconfig is missing, you need to install the net-tools package:
sudo apt update
sudo apt install net-tools -y
Now you can verify the installation:
ip --version
ifconfig --version
2. Using the ip Command
The ip command is the preferred tool for managing network interfaces in modern Linux distributions. It is part of the iproute2 package and provides various functionalities such as viewing and configuring IP addresses, routes, and network interfaces.
Displaying Network Interfaces
To list all network interfaces and their details:
ip a
or
ip addr show
This will display details such as the interface name, IP address, MAC address, and operational status.
Displaying Network Routes
To view the current routing table:
ip r
or
ip route show
Assigning an IP Address
To manually set an IP address to an interface (e.g., eth0):
sudo ip addr add 192.168.1.100/24 dev eth0
Bringing an Interface Up or Down
To enable (bring up) an interface:
sudo ip link set eth0 up
To disable (bring down) an interface:
sudo ip link set eth0 down
Configuring a Default Gateway
To set a default gateway:
sudo ip route add default via 192.168.1.1
To remove a default route:
sudo ip route del default via 192.168.1.1
3. Using the ifconfig Command
Even though ifconfig is deprecated, some users still prefer its simplicity.
Displaying Network Interfaces
To list all network interfaces:
ifconfig -a
Assigning an IP Address
To manually assign an IP address:
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up
Bringing an Interface Up or Down
To bring up an interface:
sudo ifconfig eth0 up
To bring down an interface:
sudo ifconfig eth0 down
Configuring a Default Gateway
To set a default gateway:
sudo route add default gw 192.168.1.1 eth0
To remove a default gateway:
sudo route del default gw 192.168.1.1
4. Configuring Persistent Network Settings
Changes made with ip or ifconfig are not persistent after a reboot. To make them permanent, modify the network configuration files.
Using /etc/network/interfaces
You can edit this file to configure static IP addresses:
sudo nano /etc/network/interfaces
Example configuration for a static IP:
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
Save and apply changes with:
sudo systemctl restart networking
Using netplan (if applicable)
Some newer systems use netplan for network configuration. Edit the YAML configuration file:
sudo nano /etc/netplan/01-netcfg.yaml
Example configuration:
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
Apply the changes with:
sudo netplan apply
5. Switching from ifconfig to ip
If you are accustomed to ifconfig and want to transition to ip, here are some common replacements:
ifconfig Command | Equivalent ip Command |
|---|---|
ifconfig -a | ip a or ip addr show |
ifconfig eth0 up | ip link set eth0 up |
ifconfig eth0 down | ip link set eth0 down |
ifconfig eth0 192.168.1.100 | ip addr add 192.168.1.100/24 dev eth0 |
route -n | ip route show |
route add default gw 192.168.1.1 | ip route add default via 192.168.1.1 |
Conclusion
Both ip and ifconfig commands are useful tools for managing network interfaces in Debian 12 Bookworm. While ifconfig is deprecated in favor of ip, it remains available for those who prefer the traditional method. Understanding both tools ensures you can efficiently configure and troubleshoot network settings in Debian-based systems.
For best practices, it is recommended to transition to the ip command due to its extensive features and modern capabilities. By following this guide, you now have a solid understanding of setting up and using these networking tools in Debian 12.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.