Network

Updated: 2020-12-29

Ping, sending ICMP echo request

$ ping wikipedia.org

Trace the route

$ traceroute wikipedia.org

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