Skip to main content

ifconfig is dead

Situation​

Bottom line, ifconfig has finally reached a point of scarcity that I feel I need to switch to the heir apparent iproute2. So often do I get on an isolated network that doesn't have basic tools like ifconfig, route, or vconfig and because of the environment, my workaround apt install net-tools isn't always available.

(Yet Another?) Conversion from legacy tools to iproute2.​

Below I've listed some of my common conversions from legacy tools to iproute2.

Legacy packages (with Ubuntu 22) and tools include:

  • uml-utilities - tunctl
  • bridge-utils - brctl
  • net-tools - ifconfig, route, arp, netstat
  • vlan - vconfig

Command Conversions:

  • Show all listening interfaces and their processes

    # Legacy:
    netstat -tnp
    netstat -unp

    # Modern:
    ss -tnp
    ss -unp
  • Show all interfaces

    # Legacy:
    ifconfig -a

    # Modern
    ip addr show
  • Show running interfaces

    # Legacy:
    ifconfig

    # Modern:
    ip addr show up
  • Set an IP

    # Legacy:
    ifconfig <interface> <ip>

    # Modern:
    ip addr add <ip> dev <interface>
  • Set an IP and netmask

    # Legacy:
    ifconfig <interface> <ip> netmask <netmask>

    # Modern:
    ip addr add <ip>/<maskbits> dev <interface>
  • Remove interface layer 3 addresses

    # Legacy:
    ifconfig <interface> 0.0.0.0

    # Modern:
    ip addr flush dev <interface>
  • Enable/disable interface

    # Legacy:
    ifconfig <interface> <ip> <up/down>

    # Modern:
    ip link set dev <interface> <up/down>
  • Enable only layer 2 of device.

    # Legacy:
    ifconfig <interface> 0.0.0.0 up

    # Modern:
    ip addr flush dev <interface>
    ip link set dev <interface> up
  • Change MAC Address

    # Legacy:
    ifconfig <interface> hw ether <mac>

    # Modern:
    ip link set dev <interface> address <mac>
  • View route table (numbers only)

    # Legacy:
    route -n

    # Modern:
    ip route show
  • Set default route

    # Legacy:
    route add default gw <ip>

    # Modern:
    ip route add default via <gw_ip>
    # OR
    ip route add default dev <interface>
  • Add route for a subnet via interface

    # Legacy:
    route add -net <subnet>/<maskbits> dev <interface>

    # Modern:
    ip route add <subnet>/<maskbits> dev <interface>
  • Add route for a subnet via gateway

    # Legacy:
    route add -net <subnet>/<maskbits> gw <gw_ip>

    # Modern:
    ip route add <subnet>/<maskbits> via <gw_ip>
  • Delete route for a subnet

    # Legacy:
    route del -net <subnet>/<maskbits>

    # Modern:
    ip route delete <subnet>/<maskbits> via <gw_ip>
    # OR
    ip route delete <subnet>/<maskbits> dev <interface>
  • See ARP table

    # Legacy:
    arp -an

    # Modern:
    ip neighbor show
  • Add ARP entry

    # Legacy:
    arp -s <ip> <mac>

    # Modern:
    ip neighbor add <ip> lladdr <mac> dev <interface>
  • Delete ARP entry

    # Legacy:
    arp -d <ip>

    # Modern:
    ip neighbor del <ip> lladdr <mac> dev <interface>
  • Create VLAN

    # Legacy:
    vconfig add <parent_interface> <vlan>

    # Modern:
    ip link add link <parent_interface> name <vlan_interface> type vlan id <vlan>
  • View link details (e.g. get VLAN id)

    # Legacy:
    # Encoded in interface name

    # Modern:
    ip -d link show dev <interface>
  • Create bridge interface

    # Legacy:
    brctl addbr <bridge_interface>

    # Modern:
    ip link add name <bridge_interface> type bridge
  • Add bridge port

    # Legacy:
    brctl addif <bridge_interface> <interface>

    # Modern:
    ip link set dev <interface> master <bridge_interface>
  • Delete bridge port

    # Legacy:
    brctl delif <bridge_interface> <interface>

    # Modern:
    ip link set dev <interface> nomaster
  • Create virtual interfaces (See this SO question for more info.)

    # Legacy:
    ifconfig <interface>:<veth_num> [options]

    # Modern:
    ip link add name <first_vinterface> type veth peer name <second_vinterface>
  • See tun/tap interfaces

    # Legacy:
    ifconfig -a

    # Modern:
    ip tuntap show
  • Add tun device

    # Legacy:
    tunctl [-t <tun_interface>] [-u <user>]

    # Modern:
    ip tuntap add dev <tun_interface> mode <tun/tap> [user <user> group <group>]
  • Delete tun device

    # Legacy:
    tunctl -d <tun_interface>

    # Modern:
    ip tuntap delete dev <tun_interface> mode <tun/tap>

Noteworthy Commands​

  • Rename Interface (Note: Previous used udev to do this. See this SO question.)

    # Legacy:
    nameif [options]

    # Modern:
    ip link set dev <cur_interface> name <new_interface>
  • Network Namespaces (Note: Network namespaces are only pointers in kernel space. Only iproute2 tracks its own by name.)

    # List net namespaces
    ip netns list
    # Add net namespace
    ip netns add <net_namespace>
    # Del net namespace
    ip netns del <net_namespace>
    # Run command within net namespace
    ip netns exec <net_namespace> <command>
    # Ident process net namespace
    ip netns identify <pid>
    # Assigned interface to net namespace
    # Note: Usually you can assign to pid 1 to get back to 'init_ns'
    ip link set dev <interface> <net_namespace/pid>

Training Tool​

Now that we have some conversions, we can train ourselves to stop using the old tools by replacing them with a hand smacker script. Something to say, "No! You do it this way!".

Resources​

Comments​