- Linux ip Command Examples
- Purpose
- Syntax
- Understanding ip command OBJECTS syntax
- ip command examples
- Displays info about all network interfaces
- Assigns the IP address to the interface
- Adding the broadcast address on the interface
- Remove / Delete the IP address from the interface
- Flush the IP address from the interface
- How do I change the state of the device to UP or DOWN?
- How do I change the txqueuelen of the device?
- How do I change the MTU of the device?
- Display neighbour/arp cache
- Add a new ARP entry
- Delete a ARP entry
- Change are state to reachable for the neighbour 192.168.1.100 on the device eth1
- Flush ARP entry
- ip route: Routing table management commands
- Show routing table
- List network interfaces on Linux
- Show network interfaces
- Linux
- The old way: ifconfig
- Modern version: using the ip command
- Show the default gateway
- AIX and Solaris
- DragonBSD, FreeBSD, NetBSD
- Frequently Asked Questions
- How can I see the MTU of an interface?
- What command can I use to display the default gateway on Linux?
- How can I test if my network configuration is correct?
- HowTo: Linux Show List Of Network Cards
- Use lspci command Linux command to show list of network cards
- How to use lshw command for displaying network cards (NIC) on Linux
- Linux ethtool command for Ethernet hardware devices
- ifconfig and ip commands
- Listing network cards on Linux using hwinfo command
- The /proc/net/dev file
- Conclusion
Linux ip Command Examples
I am a new Linux system admin user. How do I use ip command line utility to display or configure networking, routing, and tunnels on Linux operating systems? How do I configures or displays network interface parameters for a network using TCP/IP on Linux operating systems?
The ip command is used to assign an address to a network interface and/or configure network interface parameters on Linux operating systems. This command replaces old good and now deprecated ifconfig command on modern Linux distributions.
ip command details | |
---|---|
Description | Network configuration |
Category | Network Utilities |
Difficulty | Easy |
Root privileges | Yes |
Est. reading time | 20 mintues |
Table of contents
|
Purpose
Use this command to display and configure the network parameters for host interfaces.
Syntax
ip OBJECT COMMAND
ip [options] OBJECT COMMAND
ip OBJECT help
Understanding ip command OBJECTS syntax
OBJECTS can be any one of the following and may be written in full or abbreviated form:
Object | Abbreviated form | Purpose |
link | l | Network device. |
address | a addr | Protocol (IP or IPv6) address on a device. |
addrlabel | addrl | Label configuration for protocol address selection. |
neighbour | n neigh | ARP or NDISC cache entry. |
route | r | Routing table entry. |
rule | ru | Rule in routing policy database. |
maddress | m maddr | Multicast address. |
mroute | mr | Multicast routing cache entry. |
tunnel | t | Tunnel over IP. |
xfrm | x | Framework for IPsec protocol. |
To get information about each object use help command as follows:
ip OBJECT help
ip OBJECT h
ip a help
ip r help
Warning : The commands described below must be executed with care. If you make a mistake, you will lose connectivity to the server. You must take special care while working over the ssh based remote session.
ip command examples
Don’t be intimidated by ip command syntax. Let us get started quickly with examples.
Displays info about all network interfaces
Type the following command to list and show all ip address associated on on all network interfaces:
ip a
OR
ip addr
Sample outputs:
Fig.01 Showing IP address assigned to eth0, eth1, lo using ip command
It is also possible to specify and list particular interface TCP/IP details:
Assigns the IP address to the interface
The syntax is as follows to add an IPv4/IPv6 address:
ip a add
To assign 192.168.1.200/255.255.255.0 to eth0, enter:
ip a add 192.168.1.200/255.255.255.0 dev eth0
OR
ip a add 192.168.1.200/24 dev eth0
Adding the broadcast address on the interface
By default, the ip command does not set any broadcast address unless explicitly requested. So syntax is as follows to set broadcast ADDRESS:
ip addr add brd
ip addr add broadcast
ip addr add broadcast 172.20.10.255 dev dummy0
It is possible to use the special symbols such as + and — instead of the broadcast address by setting/resetting the host bits of the interface prex. In this example, add the address 192.168.1.50 with netmask 255.255.255.0 (/24) with standard broadcast and label “eth0Home” to the interface eth0:
ip addr add 192.168.1.50/24 brd + dev eth0 label eth0Home
You can set loopback address to the loopback device lo as follows:
ip addr add 127.0.0.1/8 dev lo brd + scope host
Remove / Delete the IP address from the interface
The syntax is as follows to remove an IPv4/IPv6 address:
ip a del
To delete 192.168.1.200/24 from eth0, enter:
ip a del 192.168.1.200/24 dev eth0
Flush the IP address from the interface
You can delete or remote an IPv4/IPv6 address one-by-one as described above. However, the flush command can remove as flush the IP address as per given condition. For example, you can delete all the IP addresses from the private network 192.168.2.0/24 using the following command:
ip -s -s a f to 192.168.2.0/24
Sample outputs:
You can disable IP address on all the ppp (Point-to-Point) interfaces:
ip -4 addr flush label «ppp*»
Here is another example for all the Ethernet interfaces:
ip -4 addr flush label «eth*»
How do I change the state of the device to UP or DOWN?
The syntax is as follows:
ip link set dev
To make the state of the device eth1 down, enter:
ip link set dev eth1 down
To make the state of the device eth1 up, enter:
ip link set dev eth1 up
How do I change the txqueuelen of the device?
You can set the length of the transmit queue of the device using ifconfig command or ip command as follows:
ip link set txqueuelen
In this example, change the default txqueuelen from 1000 to 10000 for the eth0:
ip link set txqueuelen 10000 dev eth0
ip a list eth0
How do I change the MTU of the device?
For gigabit networks you can set maximum transmission units (MTU) sizes (JumboFrames) for better network performance. The syntax is:
ip link set mtu
To change the MTU of the device eth0 to 9000, enter:
ip link set mtu 9000 dev eth0
ip a list eth0
Sample outputs:
Display neighbour/arp cache
The syntax is:
ip n show
ip neigh show
Sample outputs (note: I masked out some data with alphabets):
The last field show the the state of the “neighbour unreachability detection” machine for this entry:
- STALE – The neighbour is valid, but is probably already unreachable, so the kernel will try to check it at the first transmission.
- DELAY – A packet has been sent to the stale neighbour and the kernel is waiting for confirmation.
- REACHABLE – The neighbour is valid and apparently reachable.
Add a new ARP entry
The syntax is:
ip neigh add
In this example, add a permanent ARP entry for the neighbour 192.168.1.5 on the device eth0:
ip neigh add 192.168.1.5 lladdr 00:1a:30:38:a8:00 dev eth0 nud perm
Where,
neighbour state (nud) | meaning |
permanent | The neighbour entry is valid forever and can be only be removed administratively |
noarp | The neighbour entry is valid. No attempts to validate this entry will be made but it can be removed when its lifetime expires. |
stale | The neighbour entry is valid but suspicious. This option to ip neigh does not change the neighbour state if it was valid and the address is not changed by this command. |
reachable | The neighbour entry is valid until the reachability timeout expires. |
Delete a ARP entry
The syntax to invalidate or delete an ARP entry for the neighbour 192.168.1.5 on the device eth1 is as follows.
ip neigh del
ip neigh del 192.168.1.5 dev eth1
Change are state to reachable for the neighbour 192.168.1.100 on the device eth1
ip neigh chg 192.168.1.100 dev eth1 nud reachable
Flush ARP entry
This flush or f command flushes neighbour/arp tables, by specifying some condition. The syntax is:
ip -s -s n f
In this example, flush neighbour/arp table
ip -s -s n f 192.168.1.5
OR
ip -s -s n flush 192.168.1.5
ip route: Routing table management commands
Use the following command to manage or manipulate the kernel routing table.
Show routing table
To display the contents of the routing tables:
ip r
ip r list
ip route list
ip r list [options] ip route
Sample outputs:
Источник
List network interfaces on Linux
The network configuration is a common place to start during system configuration, security audits, and troubleshooting. It can reveal useful information like MAC and IP addresses. This guide helps you to gather this information on Linux, including listing all available network interfaces and its details.
Table of Contents
Show network interfaces
Linux
Every Linux distribution is using its own way of configuring the network configuration details. Therefore, it is good to know which tools can be used to query these details in a generic way. So these commands should be working on the popular distributions like Arch Linux, CentOS, Debian, Gentoo, RHEL, and Ubuntu.
The old way: ifconfig
Previously the most obvious command to obtain the available network interfaces was using the ifconfig command. As some systems no longer have that command installed by default, we will also look at using alternative ip. If you still have ifconfig available, run it with the -a parameter.
Depending on what particular information you need, you can use grep to get you the right lines. The ifconfig command on Linux actually has the most option available, so have a look at the man page for all details.
Modern version: using the ip command
Newer Linux distributions now ship only the ip command. It is advised to start using this command instead of ifconfig, as its output works better with newer machines. Especially when using containerized applications, dynamic routing, and network aliases.
The easiest way to see what network interfaces are available is by showing the available links.
Linux network interfaces with ip link show command
Another option to show available network interfaces is by using netstat.
Note: the column command is optional, but provides a friendlier output for the eye.
Show the default gateway
The default gateway is the system that receives traffic for networks outside your own. On Linux systems, this gateway is typically received via DHCP or manually configured in a text configuration file.
Using the ip command
The output may look like this:
With netstat
The default gateway can be listed with the netstat command.
The output will be something like this:
The second column shows the gateway. When it lists an asterisk (*), it means it uses the default gateway.
AIX and Solaris
These two old style platforms have of course ifconfig still available. By using the -a parameter, all interfaces will be displayed.
To see only the interfaces which are active, add the -u (up) parameter.
DragonBSD, FreeBSD, NetBSD
On the systems running BSD, it is also the ifconfig tool that can be used.
Frequently Asked Questions
How can I see the MTU of an interface?
Use the ip show link command.
What command can I use to display the default gateway on Linux?
Use the ip route command to show routing information, including the default gateway and the network interface it uses.
How can I test if my network configuration is correct?
Test if you can reach or access both devices on your network as outside of it. This way you know that your IP address and gateway is correctly set up. If you can only access remote systems by IP address, then check your name server configuration, typically stored in /etc/resolv.conf. Another useful tool to test your system, including your network configuration, is by using auditing tool Lynis. It will test for connectivity of the name servers and retrieves the most important parts of the network settings.
Did this article help you? Become part of the community and share it on your favorite website or social media. Do you have additional tips regarding the network configuration on Linux? Share it in the comments!
Keep learning
So you are interested in Linux security? Join the Linux Security Expert training program, a practical and lab-based training ground. For those who want to become (or stay) a Linux security expert.
Run automated security scans and increase your defenses. Lynis is an open source security tool to perform in-depth audits. It helps with system hardening, vulnerability discovery, and compliance.
Источник
HowTo: Linux Show List Of Network Cards
H ow do I display a list of all network cards under Linux operating systems?
You can use any one of the following command to list network cards installed under Linux operating systems. Please note that the ifconfig and ip commands will also display interfaces information about vpn, loopback, and other configured interfaces.
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | Yes |
Requirements | Linux |
Est. reading time | 2m |
- lspci command : List all PCI devices.
- lshw command : List all hardware.
- dmidecode command : List all hardware data from BIOS.
- ifconfig command : Outdated network config utility.
- ip command : Recommended new network config utility.
- hwinfo command : Probe Linux for network cards.
- ethtool command : See NIC/card driver and settings on Linux.
We use standard terms, such as the network interface controller (NIC). Also known as a network interface card, network adapter, LAN adapter or physical network interface, and so on. Let us see some useful examples for displing out NIC info on Linux.
Use lspci command Linux command to show list of network cards
Type the following lspci command along with egrep command to filter out devices:
# lspci | egrep -i —color ‘network|ethernet’
# lspci | egrep -i —color ‘network|ethernet|wireless|wi-fi’
Sample outputs from my Linux server:
How to use lshw command for displaying network cards (NIC) on Linux
The lshw command can extract detailed information on the hardware configuration of the machine including network cards. Type the following command:
# lshw -class network
Detailed hardware information about network cards on Linux:
Here is another outputs:
- -class network : View all network cards on your Linux system
- -short : Display device tree showing hardware paths, very much like the output of HP-UX’s ioscan
Let us see mask, IP and other information set up for wlp82s0:
$ ip a show wlp82s0
Linux ethtool command for Ethernet hardware devices
Want to see/query or control network driver and hardware settings on Linux? Try the the ethtool command:
$ sudo ethtool enp0s31f6
And it spitted out tons of useful information for my Ethernet network card on Linux:
We can display driver information for network card too:
$ sudo ethtool -i eth0
$ sudo ethtool -i enp0s31f6
ifconfig and ip commands
To see all configured network devices, enter:
# ifconfig -a
OR
# ip link show
OR
# ip a
Sample outputs:
Want to list all IP addresses and interfaces on Linux in a tabular format for better readability? Try:
$ ip -br -c link show
$ ip -br -c addr show
Listing network cards on Linux using hwinfo command
Open the terminal and then type:
$ sudo hwinfo —network —short
We can now obtain more info for eth0 using the ip command:
$ ip a s eth0
My IP address assigned to eth0:
The /proc/net/dev file
The dev pseudo-file contains network device status information. This gives the number of received and sent packets, the number of errors and collisions and other basic statistics. Open the terminal and then type the following cat command:
$ cat /proc/net/dev
Stats:
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Conclusion
We learned about various Linux commands to display information about installed and running network cards.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Category | List of Unix and Linux commands |
---|---|
Documentation | help • mandb • man • pinfo |
Disk space analyzers | df • duf • ncdu • pydf |
File Management | cat • cp • less • mkdir • more • tree |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Linux Desktop Apps | Skype • Spotify • VLC 3 |
Modern utilities | bat • exa |
Network Utilities | NetHogs • dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop |
Searching | ag • grep • whereis • which |
Shell builtins | compgen • echo • printf |
Text processing | cut • rev |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Comments on this entry are closed.
In which distro are you using the ip command? I’m trying it in Ubuntu and it seems to be a command to manipulate routing
@Chex, thanks! On Ubuntu, I was getting an error trying to run ‘ip -a’, but your command worked — and it’s very useful info.
It was a typo on part.
However, ip link show should be used.
For wireless cards I find “iwconfig” useful. I used to have problems with a wireless adapter going offline, which I worked around with “iwconfig wlan0 power off” to turn off its power management feature.
It would be most useful to correlate the HW info to the logical device name, such as the Broadcom NIC is eth1.
Try ethtool or lspci it will map both along with driver name:
Writing a shell script left as an exercise for the reader.
At any point is this site going to post anything that isn’t basic common knowledge to any linux users that isnt a complete noob?
Because if not, then I’m going to unsubscribe from your RSS feed.
I can not stop you or anyone else from unsubscribing to our RSS feed. The /faq/ section is for new users only so it has all sort of questions and answers. As you may have noticed that I’ve already started to display the difficulty level for each Q & A. I’m also working on rss feed for all three difficulties. So that users can only subscribe as follows:
- Easy – for beginners.
- Moderate – for Intermediate users.
- Hard – for Advanced users.
This is going to take a little more time as need some sort of coding and modification on my part. Hope this helps.
ok, so idioms for the easy/intermediate/hard would be ubuntu/debian/all others? ^^
Nah, but linux is no longer for those who actually are bothered to learn how to use a computer (as opposed to the in ‘noob-land’), learn how to use windows. Now, many of the windows users who are just ‘end users’ and not computer savvy, migrate to linux, and will inadvertedly land on ubuntu like distros.
I recall on youtube, some user saying, I have been using Ubuntu for 6 months and consider myself fairly knowledgable, and then went on about DE if they are installable in other distros and what not. I don’t even know what it was, but it was so absurd, I am glad that person uttered Ubuntu and not linux, as clearly the person was clueless in the latter.
You can blame Canonical for such issue. Just visit http://www.ubuntu.com/desktop home page and try to find out word Linux. I think they are ashamed of using word Linux.
PS: I use Debian Linux 🙂
[updated] Various aspects of nixCraft can be monitored with RSS feeds including ability to sort out feed – https://www.cyberciti.biz/nixcraft-rss-feed-syndication/
Hope this helps!
@root
I don’t suppose you have noticed that at least 99% of the worlds population are at least some variant of a linux ‘noob’. It would indeed be pointless to run a web site for just the 1% who are whizz kids as you would have very few visitors indeed.
Also, I believe it should be ‘to any linux user who isn’t’
I’ve clearly lost the plot a little myself, ‘at least’ and ‘indeed’ twice in above comment. Have to stop taking these tablets.
In your scripts, the easiest way is to do something like this.
for x in `/sbin/ifconfig | grep Link | awk ‘
do
echo $x
done
Or you can /sbin/ifconfig $x | grep to extract and read the data into a variable to work on later.
Here is a small code you can use in your scripts.
for x in `/sbin/ifconfig | grep Link | awk ‘
do
echo $x
done
You can replace echo $x with
/sbin/ifconfig $x | grep (any property you are looking for) and read that into a variable.
I think some of the posts are not being accepted in the comments, Vivek. Not sure why. I thought first it was something in my browser.
I sure hope I didn’t have duplicates in the comments. 🙂
We cache page for 15 minutes. So you will not see updates immediately.
how to check the nic card settings in linux
What distro?
What specifics you are looking for?
If you mean network settings for each card, depending on your distro, it can be found at
For Redhat based distros
/etc/sysconfig/network-scripts/ifcfg-[device Name]
For Debian based distros
/etc/network/interfaces
For in depth, in detail information other settings about your network card, use ethtool.
Run
man ethtool
i have dell and i have wireless in my neighbours but shows me red cross so what i do please
I am new in linux.
now I have problem with my X-Server installation.
my machine used Red Hat V7,2
and my card is used AGX3281.
this is I did for replaced the old card, but I did with the same type.
after I finished the install the X-server, and run startx,
[root@barco1 root]# startx
xinit: No such file or directory (errno 2): no server “X” in PATH
Use the — option, or make sure that /usr/X11R6/bin is in your path and
that “X” is a program or a link to the right type of server
for your display. Possible server names include:
XFree86 XFree86 displays
giving up.
xinit: Connection refused (errno 111): unable to connect to X server
xinit: No such process (errno 3): Server error.
and when I start lspci
[root@barco1 root]# lspci
00:00.0 Host bridge: Intel Corp.: Unknown device 2770 (rev 02)
00:02.0 Display controller: Intel Corp.: Unknown device 2772 (rev 02)
00:1c.0 PCI bridge: Intel Corp.: Unknown device 27d0 (rev 01)
00:1c.1 PCI bridge: Intel Corp.: Unknown device 27d2 (rev 01)
00:1c.2 PCI bridge: Intel Corp.: Unknown device 27d4 (rev 01)
00:1c.3 PCI bridge: Intel Corp.: Unknown device 27d6 (rev 01)
00:1d.0 USB Controller: Intel Corp.: Unknown device 27c8 (rev 01)
00:1d.1 USB Controller: Intel Corp.: Unknown device 27c9 (rev 01)
00:1d.2 USB Controller: Intel Corp.: Unknown device 27ca (rev 01)
00:1d.3 USB Controller: Intel Corp.: Unknown device 27cb (rev 01)
00:1d.7 USB Controller: Intel Corp.: Unknown device 27cc (rev 01)
00:1e.0 PCI bridge: Intel Corp. 82801BAM PCI (rev e1)
00:1f.0 ISA bridge: Intel Corp.: Unknown device 27b8 (rev 01)
00:1f.2 IDE interface: Intel Corp.: Unknown device 27c0 (rev 01)
00:1f.3 SMBus: Intel Corp.: Unknown device 27da (rev 01)
0b:05.0 PCI bridge: Intel Corp.: Unknown device b154
0b:0b.0 Ethernet controller: Intel Corp. 82541PI Gigabit Ethernet Controller (re
v 05)
0c:00.0 VGA compatible controller: ATI Technologies Inc: Unknown device 4c57
0c:01.0 VGA compatible controller: ATI Technologies Inc: Unknown device 4c57
0c:02.0 VGA compatible controller: ATI Technologies Inc: Unknown device 4c57
0c:03.0 VGA compatible controller: ATI Technologies Inc: Unknown device 4c57
0c:04.0 Host bridge: NEC Corporation Vrc5074 [Nile 4] (rev 03)
Источник