View network interfaces and change (spoof) MAC address in Linux

This is a basic Linux networking task and can be done via command line and graphical interface. The NetworkManager software is used to create and view network connections with graphical interface, which may look different depending on the desktop environment. Because the NetworkManager is easy to use and has a lot of front ends, this tutorial will cover only the command line method, we will use the ip and ifconfig commands, it’s recommended to use the ip command because ifconfig is obsolete, so open your favorite terminal emulator and let’s start!

Display network devices, state, MAC address, IP address, network class and statistics

As you see I have three interfaces, “lo” is the loopback interface, “eth0” the wired network card and “wlan0” the wireless card, I am using the classic naming scheme.

ip -s addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
    RX: bytes  packets  errors  dropped overrun mcast 
    2640       44       0       0       0       0        
    TX: bytes  packets  errors  dropped carrier collsns 
    2640       44       0       0       0       0            
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:00:00:00:00:01 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.2/24 brd 192.168.0.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::5ef3:fcff:feec:f454/64 scope link 
       valid_lft forever preferred_lft forever
    RX: bytes  packets  errors  dropped overrun mcast 
    149454253  137261   0       0       0       40      
    TX: bytes  packets  errors  dropped carrier collsns 
    16640485   92276    0       0       0       0       
12: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether 00:00:00:00:00:02 brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast 
    0          0        0       0       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    0          0        0       0       0       0       

Legend: Interface, State, MAC Address, IP Address, Network Class, Statistics

Or with the obsolete ifconfig

ifconfig -a
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.2  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::5ef3:fcff:feec:f454  prefixlen 64  scopeid 0x20
        ether 00:00:00:00:00:01  txqueuelen 1000  (Ethernet)
        RX packets 59133  bytes 35479715 (33.8 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 46498  bytes 9805836 (9.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  memory 0xf7ca0000-f7cc0000  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1  (Local Loopback)
        RX packets 124  bytes 7440 (7.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 124  bytes 7440 (7.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 00:00:00:00:00:02  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Legend: Interface, State, MAC Address, IP Address, Network Class, Statistics

Displaying the routing table, 192.168.0.1 is my default gateway

ip route
default via 192.168.0.1 dev eth0

Or with the obsolete route and netstat commands

route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG    0      0        0 eth0
netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG        0 0          0 eth0

Displaying DNS servers

cat /etc/resolv.conf
nameserver 192.168.0.1

Change (spoof) the MAC address

ip link set dev eth0 down
ip link set dev eth0 address 11:11:11:11:11:11
ip link set dev eth0 up

Or with the obsolete ifconfig

ifconfig eth0 down
ip link set dev eth0 address 11:11:11:11:11:11
ifconfig eth0 up

Leave a Reply

Your email address will not be published. Required fields are marked *