Skip to content

Files

Latest commit

1ccc5f7 · Jul 18, 2023

History

History
422 lines (301 loc) · 9.91 KB

Networking.md

File metadata and controls

422 lines (301 loc) · 9.91 KB

Kiwiki Home

Networking

Commands and useful cheat sheet used in networking

Check this awesome Cheat sheet

CheatSheet

Accessing a service, DNS whois = servers

Query DNS

DNS queries and shows associated records

dig $DOMAIN

Alternative to dig. It doesn't use the system local DNS.

nslookup $DOMAIN

Check packets hop and route

traceroute $DOMAIN

Network Probing

Which TCP or UDP ports are open.

Can i open a TCP connection to this destination?

Port scanning TCP,UDP ports open or closed

nmap -sS localhost

Sends ICMP pings. checks latency

ping/ping6

Test port 80 netcat

nc -lvz 80

telnet a complete protocol

tcdump -i eth0 icmp

Examine the IPv4 TCP-based sockets that are listening for connections on your system

ss -4 -tln

Examine the IPv6 TCP-based sockets that are listening for connections on your system

ss -6 -tln

Creating Unix Domain Sockets

socat unix-listen:/tmp/stream.sock,fork /dev/null&
socat unix-recvfrom:/tmp/datagram.sock,fork /dev/null&

examine unix domain sockets

ss -xln

Connect to an UNIX Socket

nc -U -z /tmp/stream.sock
  • The -U tells netcat that it is connecting to a Unix Domain Socket
  • The -z option ensures that netcat only connects to a socket, without sending any data
  • The /tmp/stream.sock is the address of the socket on the filesystem

Simulate traffic in IPV4 and IPV6

socat TCP4-LISTEN:8080,fork /dev/null&
socat TCP6-LISTEN:8080,ipv6only=1,fork /dev/null&
  • socat can listen on any available port on a system, so any port from 0 to 65535 is a valid parameter for the socket option.

Traffic capture

tcpdump traffic capture uses bpf filters tcpdump -i eth0 -vvv -d dst $IP wireshark

Network management

ifconfig see info about interfaces. get your IP address

route -n routing info. Routing table

Check ARP cache

arp -a

ip see neighbor table. add routes

  • Answers questions what are the net interfaces, ips, subnets, broadcast address?? how do i add routes?

Load testing

tcpreplay replays traffic from packet capture fire

tcpdump -i eth0 -w traffic.pcap
tcpreplay -i eth0 httptraffic.pcap

wrk2 Send Http load

Threads connections duration Requests

wrk2 -t1 -c10 -d60 -R100 -L http://$IP

Send TCP or UDP traffic. Similar to wrk2 but allows UDP

iperf3

Network performance measurement tool

nuttcp

Benchmarking

info siege

BPF/eBPF potential for new programs

source: Digital ocean talk Handy Linux networking tools

Flush DNS by resetting the network DEBIAN based

sudo /etc/init.d/networking restart

Inspect TCP socket states e.g. 443

ss -nta '( dport = :443 )'

netstat is a great tool for monitoring network connections.

Netstat statistics

netstat --statistics

Find ports in use

netstat -tulpn
  • The -t option checks for TCP connections.
  • The -u option checks for UDP connections.
  • The -l option tells netstat to list only LISTENING connections. If you want to see all connections, use the -a option instead.
  • The -p option shows the PID id of the process.
  • The -n option shows numerical addresses, instead of trying to resolve host, port, or user names.

Make sure the firewalld service is enabled

ll /usr/lib/systemd/system | grep firewalld

ll /etc/systemd/system | grep firewalld
systemctl status firewalld

sudo systemctl enable firewalld
sudo systemctl restart firewalld
sudo systemctl status firewalld

Install netcat in Fedora/Redhat

yum install -y nc

CentOS Linux Open Port 8080 on the firewall

sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload

Find user behind a process

sudo netstat -tulpe | grep 8090

Test connectivity to a port

nc -vvz $host $port

Check server status

sudo netstat -tuple | grep smtp

Check Any URL and get output in Text

curl -l localhost:80

Get listening ports

ss -tulwn

Get a report with nmap. install it first sudo snap install nmap

nmap -sV -p- localhost

The ip command

- Show / manipulate routing

ip route show

- Show List of routes

ip route list

- Show / manipulate devices

cat /etc/network/interfaces
  • Policy routing
  • Tunnels

Restart Name Service Cache Process

sudo service nscd restart

CURL Client URL

Download a file and save it with a custom name

curl -o custom_file.tar.gz https://testdomain.com/testfile.tar.gz

Get HTTP headers. use the -I or the — head option

curl -I https://www.google.com

Ignore invalid certs -k or --insecure

curl -k https://localhost/my_test_endpoint

Make a POST request.

If using JSON -H 'Content-Type: application/json'

curl --data "param1=test1&param2=test2" http://test.com

get the HTTP headers and verbose mode

curl --head --verbose HOST

Simplified view

curl --list-only $HOST

Specify the type of request

# updating the value of param2 to be test 3 on the record id
curl -X 'PUT' -d '{"param1":"test1","param2":"test3"}' \http://test.com/1

Include the Basic Auth

curl -u <user:password> https://my-test-api.com/endpoint1

Update name resolution

curl --resolve www.test.com:80:localhost http://www.test.com/

Check service health

curl -Is http://www.google.com

Upload a file

curl -F @field_name=@path/to/local_file <upload_URL>

Timing Curl connection

curl -w "%{time_total}\n" -o /dev/null -s www.test.com

VPN

OpenVPN setup in ubuntu

Back to top

Kiwiki Home