Change Grafana Default Port - Grafana Tutorials -
Medium
Sean Bradley
Photo by Haley Phelps on Unsplash
I change the default Grafana web server port from 3000 to 443 since I now have an SSL certificate
bound which I setup in Adding SSL to Grafana.
Port 443 is the default port used when you type a https:// url into the browser. Currently my
Grafana Server is accessed via
https://my-grafana-url.tld:3000
I want it to be just simply (without needing to add the port 3000)
https://my-grafana-url.tld
You have the option to change the port number to 443 in the /etc/grafana.ini file, but since
Grafana doesn’t have root privileges in Linux, it will fail to restart when trying to serve from port
443. So instead of giving the Grafana process itself escalated root privileges which would make it
less secure, I use the iptables prerouting method described below.
sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 3000
This command will redirect any external tcp requests to port 443 onto the internal port 3000
which the Grafana server process is already listening on.
After adding the rule, you can inspect the iptables settings using
iptables -t nat -L
Warning
iptables settings will be lost in case of system reboot. You will need to reapply them manually in
case you have rebooted your server,
or
also install iptables-persistent
sudo apt install iptables-persistent
This will save your settings into two files called,
/etc/iptables/rules.v4
/etc/iptables/rules.v6
Any changes you make to the iptables configuration won’t be auto saved to these persistent files,
so if you want to update these files with any changes, then use the commands,
iptables-save > /etc/iptables/rules.v4
iptables-save > /etc/iptables/rules.v6
Video Tutorial
To see the video tutorial on setting the port used to access Grafana visit,
Thankyou for reading my quick tutorial on setting the port used to access Grafana, always
remember to Clap, Comment and Share
Sean