This article hasn't been updated for over 5 years. The information below may be obsolete.
IP essentials
In later releases of the Linux OS, ip has replaced the older ifconfig to configure network interfaces. In this article we'll provide essential examples using both these commands.
Add IP address
- Using 'ifconfig':
ifconfig <interface> <ip-address> netmask <netmask-addr>
- Using 'ip':
ip addr add <ip-address>/<netmask> dev <interface>
For example to add address 10.10.10.10 with netmask 24 to device eth0
linux@host% sudo ifconfig eth0 10.10.10.10 netmask 255.255.255.0 linux@host% sudo ip addr add 10.10.10.10/24 dev eth0
Remove IP address
- Using 'ifconfig':
ifconfig <interface> <ip-address> 0.0.0.0
- Using 'ip':
ip addr del <ip-address>/<netmask> dev <interface>
For example:
linux@host% sudo ifconfig eth0 0.0.0.0 linux@host% sudo ip addr del 10.10.10.10/24 dev eth0
Down an interface
- Using 'ifconfig':
ifconfig <interface> down
- Using 'ip':
ip link set <interface> down
For example:
linux@host% sudo ifconfig eth0 down linux@host% sudo ip link set eth0 down
Up an interface
- Using 'ifconfig':
ifconfig <interface> up
- Using 'ip':
ip link set <interface> up
For example:
linux@host% sudo ifconfig eth0 up linux@host% sudo ip link set eth0 up
Enable Promiscious mode
Promiscuous mode is a network setting that lets a network interface card (NIC) capture and process all data packets on a network segment, not just those addressed to it, effectively allowing a device to "listen" to all traffic passing by.
- Using 'ifconfig':
ifconfig <interface> promisc
- Using 'ip':
ip link set <interface> promisc on
For example:
linux@host% sudo ifconfig eth0 promisc linux@host% sudo ip link set eth0 promisc on
Show device
- Using 'ifconfig':
ifconfig <interface>
- Using 'ip':
ip addr show dev <interface>
For example:
linux@host% ifconfig eth0 linux@host% ip addr show dev eth0