logo

Network

Last Updated: 2023-01-15

Ping, sending ICMP echo request

$ ping wikipedia.org

Trace the route

$ traceroute wikipedia.org

Query Name Servers:

$ nslookup wikipedia.org

Network Interface Names

Naming conventions (what you may see in ip a):

  • if it has firmware or BIOS-provided index numbers for onboard devices. => eno1
  • else if it has firmware or BIOS-provided PCI Express (PCIe) hot plug slot index numbers => ens1
  • else if it has the physical location of the connector of the hardware => enp2s0
  • else => eth0 (The traditional unpredictable kernel naming scheme.)

to config:

/usr/lib/systemd/network/99-default.link => NamePolicy

nmcli

For controlling NetworkManager.

Show connections

$ nmcli connection show

OpenSSL

$ openssl rand -base64 10
129udXpYaQJZeg==

curl

Retrieve a page

$ curl www.example.com

Save to a file

$ curl -o example.html www.example.com

Save as the origin name

$ curl -O www.example.com/example.html

Redo the request if page was moved(3XX response code)

$ curl -OL www.example.com/example.html

Get

$ curl -X GET www.example.com

Put

$ curl -X PUT --data-binary @file.xml -H "Content-type: text/xml" http://example.com/put

Use -d(--data) or --data-binary to send data.

-d sends the Content-Type application/x-www-form-urlencoded, to specify another content type, use -H "Content-Type: application/json", e.g.

$ curl -H "Content-Type: application/json" -X POST -d '{"username":"xyz","password":"xyz"}' http://localhost:3000/api/login

dig

dig (domain information groper): DNS lookup utility

Unless it is told to query a specific name server, dig will try each of the servers listed in /etc/resolv.conf

Example

$ dig google.com

; <<>> DiG 9.10.3-P4-Ubuntu <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 13686
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;google.com.			IN	A

;; ANSWER SECTION:
google.com.		8	IN	A	xxx.xxx.xxx.xxx

;; Query time: 16 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Thu Jan 01 20:24:55 PDT 2020
;; MSG SIZE  rcvd: 55

DNS

/etc/systemd/resolved.conf