outils ip sous Ubuntu
Comparison of ip and ifconfig commands
For this comparison, we’ll use a number of examples to demonstrate how things are done with ip command and similar commands used with ifconfig. Since both commands are available on all Linux distributions, you can stick with what you’re comfortable with. If you’ve been an ifconfig user for a long time now, this guide will introduce you to commands enough to get you started with ip tool.
In all examples, any command with prefix ifconfig is specific to the ifconfig tool and any command starting with ip is specific to the ip network management tool. So keep this in mind as you proceed.
Display network interfaces and ip address information
To get all IP address related information using ip/ifconfig, these commands are used.
$ ifconfig
$ ip addr
Take down/up network interface:
If you would like to take down or bring up an interface, this is often done when modifying network configurations, you can use below commands. The interface eth0 can be replaced with any other interface name.
sudo ifconfig eth0 {up|down}
sudo ip link set dev eth0 {up|down}
Set a static IP and netmask:
Static IP setting can be done using ip or ifconfig. But note that changes made with these commands are not persistent against reboots. Explore setting static ip using the nmcli tool or by modifying network configuration file on your distribution for permanent changes. Some guides available on this blog are:
Example:
sudo ifconfig eth0 192.168.1.10 netmask 255.255.255.0
sudo ip addr add 192.168.1.10/34 dev eth0
Remove static IP address:
To clear ip address information for an interface commands syntax is as below for both tools:
sudo ifconfig eth0 del 192.168.1.10
sudo ip addr del 192.168.1.10/24 dev eth0
Set network MTU
MTU is an abbreviation for maximum transmission unit. In networking, this is the size of the largest network layer protocol data unit that can be communicated in a single network transaction. In this example, mtu size of 1500 bytes is set. Larger MTU values is common for storage servers/systems.
sudo ifconfig eth0 mtu 1500
sudo ip link set dev eth0 mtu 1500
Enable Promiscuous Mode
Promiscuous mode is a mode of operation in networking whereby every data packet transmitted can be received and read by a network adapter. This is often used to monitor network activity.
sudo ifconfig eth0 promisc
sudo ip link set dev eth0 promisc on
Enable ARP
The Address Resolution Protocol is a communication protocol used for discovering the link layer address associated with a given IPv4 address, a critical function in Internet Protocol computer networks. To enable it to run the commands:
sudo ifconfig eth0 arp
sudo ip link set dev eth0 arp on
Set MAC address
ip and ifconfig commands can do runtime change of MAC address. In this example, we’re setting MAC address to aa:bb:cc:dd:ee:ff. Note that each NIC has fixed mac address which cannot be changed, changing mac address is not recommended since it can cause issues on layer 2 network communication if any collision exists.
sudo ifconfig eth0 hw ether aa:bb:cc:dd:ee:ff
sudo ip link set dev eth0 address aa:bb:cc:dd:ee:ff
Add default route via gateway IP
A default route can be set using ip and ifconfig commands for destinations without static routes defined.
sudo route add default gw 192.168.1.1
sudo ip route add default via 192.168.1.1
Set Static route
Static route defines a destination to a specific network. In this example, we’re specifying that all packets destined for 192.168.3.0/24 network must go through 192.168.1.1 gateway. The network interface to the default gateway is eth0.
sudo route add -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.1.1
sudo ip route add 192.168.3.0/24 via 192.168.1.1 dev eth0
A different guide to Setting up Static routes on Linux is available on this blog. Please read it to strengthen the knowledge already accumulated here.
View neighbors (using ARP and NDP):
To check ARP table, run:
$ ip neighbor showip addr
Display the current default route.
$ ip route show | head -n 1
Remove default gw
If you no longer need the default gateway set and would like to change, you can delete currently set using:
$ ip route del default via 62.12.113.1 dev eth1
Créé avec HelpNDoc Personal Edition: Modernisez vos fichiers d'aide avec l'outil de conversion WinHelp HLP vers CHM de HelpNDoc