When a site won't open, the problem can be in several places. The name isn't found, the server (the computer that runs the site) can't be reached, or the app (the site's program, for example a Node program) inside the server has stopped. The network tools in your terminal check those places one at a time. Picture delivering a parcel to a friend's office:
- Look up the office's address:
digfinds the server's IP address. - Check that the building can be reached:
pingchecks the server computer. - Ask the receptionist in the lobby:
curl -Iasks the site. - Check that your friend is at their desk:
sschecks the app.
As soon as one step fails, you know where the problem is.
dig: a domain name becomes an IP address
Computers reach a server by its IP address (an address made of numbers). So the first step is always turning the domain name (such as belajarweb.dev) into an IP address through DNS, the internet's address book. dig asks DNS, then shows the answer:
$ dig belajarweb.dev
; <<>> DiG 9.18.28 <<>> belajarweb.dev
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41872
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;belajarweb.dev. IN A
;; ANSWER SECTION:
belajarweb.dev. 300 IN A 203.0.113.10
;; Query time: 24 msec
;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
;; WHEN: Thu Oct 08 07:37:02 UTC 2026
;; MSG SIZE rcvd: 59
status: NOERRORmeans the question was answered. When the name isn't registered, the status isNXDOMAINandANSWER: 0.- The line under ANSWER SECTION is the answer. In order: the name, the TTL,
IN A, then the IP address,203.0.113.10. The TTL is how many seconds this answer may be kept in a cache (a temporary store), here 300.IN Ameans a record (an entry) of type A, which holds an IPv4 address (an IP address made of four numbers). dig belajarweb.dev +shortshows only the IP address:203.0.113.10.
ping: can the server be reached?
ping sends small packets (pieces of data) to a machine, here the server computer, then measures how long the replies take:
$ ping -c 3 belajarweb.dev
PING belajarweb.dev (203.0.113.10) 56(84) bytes of data.
64 bytes from 203.0.113.10: icmp_seq=1 ttl=54 time=12.4 ms
64 bytes from 203.0.113.10: icmp_seq=2 ttl=54 time=11.9 ms
64 bytes from 203.0.113.10: icmp_seq=3 ttl=54 time=12.1 ms
--- belajarweb.dev ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 11.900/12.133/12.400/0.205 ms
-c 3means send 3 packets, then stop. Without-c, ping on Linux keeps going until you press Ctrl+C.time=12.4 msis the time for one packet to go there and back, in milliseconds.0% packet lossmeans every packet got a reply.
Now picture the Node app on the server stopping while the server computer itself stays on. Does ping belajarweb.dev succeed or fail? Guess before you continue reading.
It succeeds. ping only checks the machine, not the app inside it. And a failed ping doesn't prove the site has stopped, because some servers refuse ping on purpose.
curl -I: what does the site answer?
curl sends a request to a site, then shows the response (the server's answer): the headers (information about the answer, including the status code) and the body (the page itself). curl -I sends a HEAD request, which asks for the headers only, without the body. It's a quick way to check the status code (a number that shows the result):
$ curl -I https://belajarweb.dev
HTTP/2 200
server: nginx/1.24.0 (Ubuntu)
date: Thu, 08 Oct 2026 07:37:02 GMT
content-type: text/html; charset=utf-8
content-length: 5120
cache-control: public, max-age=600
The status code is on the first line: 200, which means success. The server: line shows who answered: nginx, a program that receives visitors and passes each request on to the app behind it. When the Node app behind nginx has stopped, nginx still answers, but with HTTP/2 502 (Bad Gateway): "I'm alive, but the app behind me can't be reached". When the domain name isn't in DNS, curl stops before sending anything: curl: (6) Could not resolve host: api.belajarweb.dev.
curl -v shows all the details: lines starting with > are the request it sent, lines starting with < are the server's response. The -v output goes to stderr, and a pipe only carries stdout. So to filter it with grep you have to merge it into stdout first with 2>&1:
curl -v https://belajarweb.dev 2>&1 | grep "< HTTP"
# < HTTP/2 200
ss and netstat: who listens on which port?
One server can run several apps, and each app uses its own port number, like a desk number in an office. An app that is ready to accept connections is said to listen on its port. ss -tlnp (TCP, listening, numbers, process) shows them all:
$ sudo ss -tlnp
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=701,fd=3))
LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=812,fd=6))
LISTEN 0 511 0.0.0.0:443 0.0.0.0:* users:(("nginx",pid=812,fd=7))
LISTEN 0 511 127.0.0.1:3000 0.0.0.0:* users:(("node",pid=4821,fd=21))
LISTEN 0 244 127.0.0.1:5432 0.0.0.0:* users:(("postgres",pid=903,fd=6))
0.0.0.0:443means nginx accepts connections from anywhere, on port 443.127.0.0.1:3000means Node only accepts connections from the server itself, on port 3000. That is why visitors go through nginx first.- When the Node app stops, the
127.0.0.1:3000line disappears from the list. lsof -i :3000starts from one port: it shows the process that is using port 3000.
$ sudo lsof -i :3000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 4821 deploy 21u IPv4 38212 0t0 TCP localhost:3000 (LISTEN)
netstat is an older tool that ss replaced, but you'll still see it often. netstat -tan shows the columns Proto, Recv-Q, Send-Q, Local Address, Foreign Address and State. The states you'll see most: LISTEN (waiting for connections), ESTABLISHED (a connection is open), and TIME_WAIT (a connection just closed and will be removed soon).
The commands above are for a Linux server. On your laptop, the commands depend on its operating system (name in the table is a domain name, for example belajarweb.dev):
| System | Who is listening | Who uses port 3000 | Send 3 pings |
|---|---|---|---|
| Linux | ss -tlnp |
lsof -i :3000 |
ping -c 3 name |
| macOS | lsof -nP -iTCP -sTCP:LISTEN (there is no ss) |
lsof -i :3000 |
ping -c 3 name |
| Windows (PowerShell) | Get-NetTCPConnection -State Listen |
Get-NetTCPConnection -LocalPort 3000 |
ping -n 3 name |
On macOS, netstat writes the port after a dot, not a colon: 127.0.0.1.3000, not 127.0.0.1:3000. On Windows, the OwningProcess column of Get-NetTCPConnection holds the PID (process number) that uses that port.
What you write in the exercise: a netstat output parser
In the exercise, your code reads a short version of netstat output. The Recv-Q and Send-Q columns are dropped, so each line has four columns: proto, local address, foreign address (the address at the other end) and state. This is the output it reads:
| Line | proto | local | foreign | state |
|---|---|---|---|---|
| 1 | tcp | 127.0.0.1:3000 | 0.0.0.0:* | LISTEN |
| 2 | tcp | 192.168.1.5:52341 | 93.184.216.34:443 | ESTABLISHED |
| 3 | tcp | 127.0.0.1:5432 | 0.0.0.0:* | LISTEN |
| 4 | tcp | 192.168.1.5:52342 | 8.8.8.8:53 | TIME_WAIT |
This code splits one line into four columns:
const line = "tcp 127.0.0.1:3000 0.0.0.0:* LISTEN";
const [proto, local, foreign, state] = line.trim().split(/\s+/);
console.log(local); // 127.0.0.1:3000
console.log("listen".toLowerCase() === state.toLowerCase()); // true
trim()removes the spaces at the start and end of the line. Thensplit(/\s+/)splits it at one or more spaces, and the four names in[...]receive the four columns in order.split(" ")would leave empty strings between two spaces, so the columns shift.- In the exercise, you split the full output into lines with
split("\n"), drop the empty lines, then turn each line into an object. - You also look for the lines with a given state.
toLowerCase()(turn into lower case) on both sides makes"established"matchESTABLISHED. The four lines in the table hold 2 LISTEN and 1 ESTABLISHED. When nothing matches, the result is an empty array, with length 0.
⚠️ Misreading what the network checks say
- Thinking a successful ping means the site is healthy. Ping only proves the machine is alive. Check the site with
curl -I, and the app withss -tlnp. - Forgetting
2>&1when filteringcurl -v. The-vdetails are on stderr, socurl -v url | grep "< HTTP"finds nothing. - Mixing up 127.0.0.1 and 0.0.0.0. An app listening on
127.0.0.1can't be opened from outside the server, even with the right port. - Splitting a line at single spaces. In terminal output, the gap between columns can be several spaces. Use
/\s+/, drop empty lines, and compare states without caring about upper or lower case.
TL;DR: When a site won't open, check in order. dig name (or +short): does the name become an IP address through DNS (the internet's address book)? NXDOMAIN means the name isn't registered. ping -c 3 name: can the server machine be reached? Ping checks the machine, not the app (the site's program) inside it. curl -I url: the headers (information about the server's answer) only, with no body (the page itself). Status code 200 is healthy, 502 means nginx (the program that receives visitors) is alive but the app behind it has stopped. curl -v url 2>&1 | grep "< HTTP" keeps only the status line from the full -v details. On the server, ss -tlnp (or netstat) shows who LISTENs (waits for connections) on which port. A port is a number that tells the apps on one server apart. lsof -i :3000 shows the process using port 3000. The states (connection statuses) that matter: LISTEN, ESTABLISHED (connected) and TIME_WAIT (just closed).
⚡ A name becomes an IP
Write:
dig belajarweb.dev +short
Meaning: Computers reach a server by its IP address (an address made of numbers), so the first step is always turning the site's name into an IP. dig asks DNS (the internet's address book), and +short shows only the IP. NXDOMAIN means the name isn't registered.
⚡ Is the machine alive?
Write:
ping -c 3 belajarweb.dev
Guess first: ping sends small data packets to a machine and waits for replies. The Node app (the site's program) on the server has stopped, but the server machine is on. Does ping succeed or fail?
It succeeds. ping only checks the machine, not the app inside it.
Meaning: -c 3 means send 3 packets, then stop. 0% packet loss means every packet got a reply.
⚡ What does the site answer?
Write:
curl -I https://belajarweb.dev
Meaning: curl sends a request to the site, and -I asks for the headers only: information about the server's answer, including the status code, without the page itself. Status code 200 means healthy, 502 means nginx (the program that receives visitors) is alive but the app behind it has stopped.
⚡ Who's using this port?
Write:
sudo lsof -i :3000
Meaning: A port is a number that tells the apps on one server apart. This command shows the process using port 3000. ss -tlnp lists every app with the port it listens on (waits for connections on).