Skip to content

Servers & Networks

Port forwarding

Using SSH

The machine has a web server running on port 8000 internally (not exposed to the internet). With the following command you can now access the web server from http://localhost:4444.

ssh -L 4444:localhost:8000

SMTP Server

Setup a SMTP server with Python.

$ sudo python3 -m smtpd -n -c DebuggingServer
---------- MESSAGE FOLLOWS ----------
b'Date: Sun, 26 Sep 2021 18:21:06 +0200'
b'Subject: test Sun, 26 Sep 2021 18:21:06 +0200'
b'Message-Id: <20210926182106.026180@arch.localdomain>'
b'X-Mailer: swaks vDEVRELEASE'
b'This is a test mailing'
------------ END MESSAGE ------------

Command to send the mail :

$ swaks --to --from --server localhost

HTTP Server

Setup a HTTP server with Python.

$ python3 -m http.server --bind 4444
Serving HTTP on port 4444 ( ... - - [26/Sep/2021 18:24:47] code 404, message File not found - - [26/Sep/2021 18:24:47] "GET /hello HTTP/1.1" 404 -

Command to the the HTTP request :

$ curl localhost:4444/hello


Use tcpdump to listen for ping request and reply.

$ sudo tcpdump icmp -n
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on wlp3s0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
18:53:25.737055 IP > ICMP echo request, id 1, seq 1, length 64
18:53:25.737224 IP > ICMP echo reply, id 1, seq 1, length 64

TCP connections

Add iptables rule that listen for new TCP connections.

$ sudo iptables -A INPUT -p tcp -m state --state NEW -j LOG --log-prefix "New TCP connection: " -i wlp3s0


To remove the rule from iptables, execute the same commands but replace the -A with -D.

View the log :

$ journalctl -k --grep='New TCP connection: '
Sep 26 19:04:24 arch kernel: [NEW TCP connection] IN=wlp3s0 OUT= MAC=XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX SRC= DST= LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=25957
Back to top