Showing posts with label IP. Show all posts
Showing posts with label IP. Show all posts

Tuesday, September 19, 2023

IP command Cheat Sheet

Several of the most used Linux commands/tools such as ifconfig, netstat, route is deprecated. It’s time to start using the versatile ip command line utility.

 

Ip command line utility provided by the ‘net-tools’ package is used for various network administration tasks on Linux nodes.

 

Syntax of the ip command line utility:

 

# ip [ OPTIONS ] OBJECT { COMMAND | help}

 

OPTIONS are used to define global parameters. Commonly used ones being:

-4 -> shows IPv4 specific details only.

-6 -> shows IPv6 specific details only.

-s -> shows statistics of the various network interfaces.

-t -> display current time when using monitor option.

 

 

OBJECTS are the items the command would action on.

Commonly used OBJECTS are the follows:

 

OBJECT

Abbreviation

Used for

address

a, addr

IP address on the device

link

l

Network device

route

r

Routing table entry

rule

ru

Rule in the routing policy database

neighbour

n, neigh

Manage ARP/NDSC cache entries

maddress

m, maddr

Multicast address

monitor

 

Watch netlink messages

 

 

This cheat sheet offers a concise overview of the ip command and its available options. It serves as a valuable resource for troubleshooting network and system issues."

 

NOTE: The commands have certain parameters mentioned in capital letters like ‘INTERFACE’, this needs to be changed depending on your use case.

1. Displaying Network Information:

  • ip address show or ip a : Show information about all network interfaces.
  • ip link show or ip l : Display link layer information.
  • ip route show or ip r : Display the routing table.

2. Managing Network Interfaces:

  • ip link set dev INTERFACE up/down : Enable or disable a network interface.
  • ip link set dev INTERFACE name NEW_NAME : Rename a network interface.
  • ip link set dev INTERFACE mtu MTU_VALUE : Set the Maximum Transmission Unit (MTU) for an interface.
  • ip link add link INTERFACE name NEW_INTERFACE type TYPE : Create a new virtual interface based on an existing one.

3. Configuring IP Addresses:

  • ip address add IP_ADDRESS/NETMASK dev INTERFACE : Assign an IP address to an interface.
  • ip address delete IP_ADDRESS/NETMASK dev INTERFACE : Remove an IP address from an interface.
  • ip address show dev INTERFACE : Display IP address information for a specific interface.

4. Managing Routes:

  • ip route add NETWORK via GATEWAY : Add a static route.
  • ip route delete NETWORK : Delete a static route.
  • ip route show : Display the routing table.
  • ip route flush cache : Clear the routing cache.

5. Managing ARP Cache:

  • ip neigh show : Display the ARP cache.
  • ip neigh add IP_ADDRESS lladdr MAC_ADDRESS dev INTERFACE : Add an ARP cache entry manually.
  • ip neigh delete IP_ADDRESS dev INTERFACE : Delete an entry from the ARP cache.

6. Managing VLANs (Virtual LANs):

  • ip link add link INTERFACE name VLAN_NAME type vlan id VLAN_ID : Create a VLAN interface.
  • ip link show VLAN_NAME : Display information about a VLAN interface.

7. Managing Bridge Interfaces:

  • ip link add name BRIDGE_NAME type bridge : Create a bridge interface.
  • ip link set dev INTERFACE master BRIDGE_NAME : Add an interface to a bridge.
  • ip link set dev INTERFACE nomaster : Remove an interface from a bridge.
  • ip link show BRIDGE_NAME : Display information about a bridge.

8. Managing Tunnels:

  • ip tunnel add TUNNEL_NAME mode MODE remote REMOTE_IP local LOCAL_IP : Create a tunnel interface.
  • ip tunnel delete TUNNEL_NAME : Delete a tunnel interface.
  • ip tunnel show : Display information about tunnel interfaces.

9. Managing QoS and Traffic Control:

  • ip link set dev INTERFACE qlen QUEUE_LENGTH : Set the length of the transmit queue.
  • ip link set dev INTERFACE txqueuelen QUEUE_LENGTH : Set the length of the transmit queue.
  • tc : Use the tc command for advanced traffic control and QoS configuration.

10. Managing Multicast:

  • ip maddr show : Display multicast group memberships.
  • ip maddr add IP_ADDRESS dev INTERFACE : This adds the INTERFACE to the membership of the multicast group with an  IPv4 address of IP_ADDRESS.
  • ip maddr delete IP_ADDRESS dev INTERFACE : Leave the INTERFACE from the multicast group with ip address IP_ADDRESS.

This ip command cheat sheet should provide you with a quick reference for managing network configurations and interfaces in Linux.

Remember to replace INTERFACE, IP_ADDRESS, NETMASK, NETWORK, GATEWAY, VLAN_NAME, BRIDGE_NAME, TUNNEL_NAME, REMOTE_IP, LOCAL_IP, QUEUE_LENGTH, and other placeholders with your specific values when using the commands.

 

Thursday, April 25, 2013

Assign IP Address and Gateway in Linux from Command Line

if config command is used to assign the ip address to a lan card from the command or from the terminal.

Syntax :

 # ifconfig [-v] [-a] [-s]  [interface]

Options :
  • -a :    display all interfaces which are currently available, even if down
  • -s :    display a short list (like netstat -i)
  • -v :   be more verbose for some error conditions
interface : The name of the interface.  This is usually a driver name followed by a unit number, for example eth0 for  the  first Ethernet interface. If your kernel supports alias interfaces, you can specify them with eth0:0 for the first alias of eth0. One can use them to assign a second address. To delete an alias interface use ifconfig eth0:0 down.

Monday, September 20, 2010

Network Interface Configuration in Ubuntu 10.04 LTS Lucid Lynx

Normally all the users will create and configure their network while installing the Operating System Itself. However here I am post the process of configuring the network using command line in Ubuntu 10.04 LTS Lucid Lynx. You can also configure network using GUI utilities in Ubuntu 10.04 LTS such as network-admin or else your famous ifcfg command etc.


Here I am following the bare metal method and will edit the main network configuration files for providing the network information. The main network configuration file of any Ubuntu based distribution is the "/etc/network/interfaces" file. Just open the file in your favourite editor and start configuring it as follows.

Tuesday, April 13, 2010

Set multiple IPs in single nic.

Hello guys...
Ever wondered how to set multiple IPs in a single network card? Here is the solution.

Multiple IP binded in a single network card allows you run different services in different IPs, for example you can run HTTP on one IP and SMTP on another IP or a private LAN using a local IP and the alias holding your Public IP. The major benifit here is that you do not need an additional physical adaptor, you can bind many virtual IPs to a single network card. Here I have explained the procedure for creating multiple IPs for RedHat based and Debian bases systems

Redhat based systems.

Let me assume that your NIC is bound with a static IP address. Go to the folder /etc/sysconfig/network-scripts/, there you will find your network configuration files.

# cd /etc/sysconfig/network-scripts/

Let me also guess that your machine has only one network card (can be onboard too!!!), then you will find a file ifcfg-eth0 in the folder. This file holds the IP information for the first nic. If your machine has more nics you will have ifcfg-eth1, ifcfg-eth2 and so on... Now open the ifcfg-eth0 file, you can view the network configuration as below:

# cat ./ifcfg-eth0# File: ifcfg-eth0


DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.120
NETMASK=255.255.255.0
BROADCAST=192.168.1.255
NETWORK=192.168.1.0
HWADDR=xx:xx:xx:xx:xx:xx


Now to bind another IP address to the same network card, you just have to copy the ifcfg-eth0 file to ifcfg-eth0:1.
 
# cp ./ifcfg-etho ./ifcfg-eth0:1