Net-tools to iproute2: Difference between revisions

From Leo's Notes
This page was last edited on 28 October 2022, at 21:40.
mNo edit summary
mNo edit summary
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
The following maps the deprecated network tools (ifconfig, route, netstat, etc) to the new ip command.
The deprecated {{code|net-tools}} package contains all legacy network tools such as {{code|ipconfig}}, {{code|route}}, {{code|arp}}, etc.  Since tools from {{code|net-tools}} are now obsolete, it is best practice to move towards using the replacement commands provided by {{code|iproute2}}.


The following table maps common {{code|net-tools}} based commands to the new {{code|iproute2}} commands.  Note that most {{code|iproute2}} sub commands can be specified with the shortest unambiguous name (ie. {{code|a}} or {{code|addr}} for {{code|address}}). The unambiguous name is marked in bold.
{| class="wikitable"
{| class="wikitable"
|-
|-
! Old
! width="20%" |Description
! New
!Old {{code|net-tools}}
!New {{code|iproute2}}
|-
|-
| ifconfig
|Show ARP table
| ip addr
|{{code|arp -n}}
|{{code|ip '''n'''eighbour}}
|-
|-
| ifconfig $interface <nowiki>[up|down]</nowiki>
|Show listening ports
| ip link set dev $interface <nowiki>[up|down]</nowiki>
|{{code|netstat -ln}}
|{{code|ss -ln}}
|-
|-
| ifconfig $interface $ip netmask $netmask
|Shows routing table
| ip addr add $ip/$mask dev $interface
|{{code|netstat -r}}
|{{code|ip '''r'''oute}}
|-
|-
| route add default gw $gateway
|shows network interface counters
| ip route add default via $gateway
|{{code|netstat -i }}
|{{code|ip -s '''l'''ink}}
|-
|-
| route add -net $net netmask $netmask gw $gateway
|Show interface group memberships
| ip route add $net/$mask via $gateway
|{{code|netstat -g}}
|{{code|ip maddr}}
|-
|-
| route -n
|Wireless config
| ip route
|{{code|iwconfig}}
|{{code|iw}}
|-
|IP Tunnel configuration
|{{code|iptunnel}}
|{{code|ip '''t'''unnel}}
|-
|Shows interfaces based on MAC address
|{{code|nameif}}
|{{code|ip '''l'''ink}}
|-
|Shows interface addresses
|{{code|ifconfig}}
|{{code|ip '''a'''ddress}}
|-
|Bring an interface up or down
|{{code|ifconfig $interface <nowiki>[up|down]</nowiki>}}
|{{code|ip '''l'''ink set dev $interface <nowiki>[up|down]</nowiki>}}
|-
|Renames eth0 to eth1, where {{code|xx:xx:xx:xx:xx:xx}} is eth0's MAC address
|{{code|nameif eth1 xx:xx:xx:xx:xx:xx}}
|{{code|ip link set dev eth0 name eth1}}
|-
|Changes interface MAC address
|<code>ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx</code>
|<code>ip link set dev eth0 address xx:xx:xx:xx:xx:xx</code>
|-
|Sets the MTU for eth0 to 1500
|{{code|ifconfig eth0 mtu 1500}}
|{{code|ip link set dev eth0 mtu 1500}}
|-
|Change an interface IP address.
Requires remove/add in {{code|iproute2}}.
|{{code|ifconfig $interface $ip [netmask $netmask]}}
|{{code|ip '''a'''ddr del $ip/$mask dev $interface <br /> ip '''a'''ddr add $ip/$mask dev $interface}}
|-
|Adds a secondary IP to an interface. Old net-tools uses interface:X to denote secondary addresses (eg. {{code|eth0:0}}).
|{{code|ifconfig $interface:X $ip [netmask $netmask]}}
|{{code|ip '''a'''ddr add $ip/$mask dev $interface}}
|-
|Removes the IP address on an interface
|{{code|ifconfig $interface 0.0.0.0}}
|{{code|ip '''a'''ddr del $ip/$mask dev $interface}}
|-
|Adds a default gateway
|{{code|route add default gw $gateway}}
|{{code|ip '''r'''oute add default via $gateway}}
|-
|Removes a default gateway
|{{code|route del default gw $gateway}}
|{{code|ip '''r'''oute del default via $gateway}}
|-
|Adds a static route via a gateway
|{{code|route add -net $net netmask $netmask gw $gateway}}
|{{code|ip '''r'''oute add $net/$mask via $gateway}}
|-
|Deletes a static route
|{{code|route del -net $net gw $gateway netmask $netmask dev $device}}
|{{code|ip '''r'''oute del $net/$mask via $gateway}}
|-
|Shows routing table
|{{code|route -n}}
|{{code|ip '''r'''oute}}
|}
|}


Like networking commands on switches and routers, you do not need to write the full command name so long as the beginning of the command is uniquely identifiable. For example, <code>ip address</code> can be simplified to <code>ip a</code> and <code>ip route</code> can be simplified to <code>ip r</code>.
== See also ==
 
The <code>ip address add $ip/$mask dev $interface</code> will add additional IP addresses to the device. If it already has an existing IP address, you will need to use <code>ip address del $ip/$mask dev $interface</code> to remove it.
 


* Some other commands: http://unix.stackexchange.com/questions/152331/how-can-i-create-a-virtual-ethernet-interface-on-a-machine-without-a-physical-ad
{{Navbox Linux}}
[[Category:Linux]]
[[Category:Linux]]
[[Category:Networking]]
[[Category:Networking]]
{{Navbox Linux}}

Latest revision as of 21:40, 28 October 2022

The deprecated net-tools package contains all legacy network tools such as ipconfig, route, arp, etc. Since tools from net-tools are now obsolete, it is best practice to move towards using the replacement commands provided by iproute2.

The following table maps common net-tools based commands to the new iproute2 commands. Note that most iproute2 sub commands can be specified with the shortest unambiguous name (ie. a or addr for address). The unambiguous name is marked in bold.

Description Old net-tools New iproute2
Show ARP table arp -n ip neighbour
Show listening ports netstat -ln ss -ln
Shows routing table netstat -r ip route
shows network interface counters netstat -i ip -s link
Show interface group memberships netstat -g ip maddr
Wireless config iwconfig iw
IP Tunnel configuration iptunnel ip tunnel
Shows interfaces based on MAC address nameif ip link
Shows interface addresses ifconfig ip address
Bring an interface up or down ifconfig $interface [up|down] ip link set dev $interface [up|down]
Renames eth0 to eth1, where xx:xx:xx:xx:xx:xx is eth0's MAC address nameif eth1 xx:xx:xx:xx:xx:xx ip link set dev eth0 name eth1
Changes interface MAC address ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx ip link set dev eth0 address xx:xx:xx:xx:xx:xx
Sets the MTU for eth0 to 1500 ifconfig eth0 mtu 1500 ip link set dev eth0 mtu 1500
Change an interface IP address.

Requires remove/add in iproute2.

ifconfig $interface $ip [netmask $netmask] ip addr del $ip/$mask dev $interface
ip addr add $ip/$mask dev $interface
Adds a secondary IP to an interface. Old net-tools uses interface:X to denote secondary addresses (eg. eth0:0). ifconfig $interface:X $ip [netmask $netmask] ip addr add $ip/$mask dev $interface
Removes the IP address on an interface ifconfig $interface 0.0.0.0 ip addr del $ip/$mask dev $interface
Adds a default gateway route add default gw $gateway ip route add default via $gateway
Removes a default gateway route del default gw $gateway ip route del default via $gateway
Adds a static route via a gateway route add -net $net netmask $netmask gw $gateway ip route add $net/$mask via $gateway
Deletes a static route route del -net $net gw $gateway netmask $netmask dev $device ip route del $net/$mask via $gateway
Shows routing table route -n ip route

See also