Post

Linux Networking

Linux Networking

In this post I describe simple network configuration steps of Linux servers and some commands for troubleshooting and testing.

Get network adapters

1
ip -c a

Output should look like:

1
2
3
4
5
6
7
8
9
10
11
12
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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 noprefixroute 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 0c:9d:92:11:22:33 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.16/24 brd 192.168.0.255 scope global dynamic noprefixroute eth0
       valid_lft 730sec preferred_lft 730sec
    inet6 fe80::1e2a:5533/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

Now you know that your network adapter is eth0. Depending on the distribution you use other names like enp0s1 are also possible.

Configure static ip-address

Edit /etc/network/interfaces.

1
2
3
4
5
6
auto eth0
iface eth0 inet static
 address 192.168.0.4
 netmask 255.255.255.0
 gateway 192.168.0.1
 dns-nameservers 192.168.0.1 100.100.100.100

When finished restart network service.

1
systemctl restart networking

or

1
ifdown --all; ifup --all

or

1
ifdown eth0; ifup eth0

Show listinening (open) ports on the server

1
ss -lntp

Output shoud look something like this:

1
2
3
State   Recv-Q  Send-Q   Local Address:Port   Peer Address:Port Process                                 
LISTEN  0       32       192.168.122.1:53          0.0.0.0:*                                            
LISTEN  0       50                   *:1716              *:*     users:(("kdeconnectd",pid=1613,fd=21)) 

In this case, e.g. my linux client has an opend port for DNS (53) and 1716 which is used by KDEConnect.

Who’s logged in right now?

1
w

Output looks like:

1
2
3
4
user@server:~$ w
 13:00:46 up 6 days, 16:44,  1 user,  load average: 3.84, 2.82, 2.96
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
user1   pts/0    192.168.0.16     13:00    0.00s  0.09s  0.02s cat /etc/shadow

Beside the logged in user you alse see the last executed command in the last row (WHAT?!)

This post is licensed under CC BY 4.0 by the author.