Share Your Hexo Website within Local Network

After building our own website using Hexo, we can use the following command to preview the website on our own PC:

1
2
3
hexo clean
hexo g
hexo s

With the default setup, we can visit the website on http://localhost:4000. However, if we want share the website with colleagues in the same local network without publishing the website, we need to open the port to the local domain. The commands are shown as below:

1
2
3
4
5
6
7
8
9
10
# list all the port
# l - listening
# n - with port number
# t - tcp
# u - udp
netstat -lntu
# search for port number 4000
netstat -na | grep :4000
# if using ubuntu firewall
sudo ufw allow 4000

For Ubuntu 20.04, ufw will manage all the connections and ports, however, for other Linux release versions, we can using iptables as follows:

1
2
3
4
5
6
7
8
9
10
# centos & redhat
firewall-cmd --add-port=4000/tcp
# iptable
# A - append new protocal
# p - protocal
# --dport -
# j - jump
iptables -A INPUT -p tcp --dport 4000 -j ACCEPT
# restart iptables
sudo systemctl restart iptables