I have a MySQL server running on port 3306 with a private IP: 10.64.30.117. I also have a web app running on another node with a private IP: 10.17.23.1.
I want the web app to be able to access the MySQL server but I don't want MySQL to be publicly available. (Both nodes have a public IP too).
I tried using UFW but it seems to block everything, the ufw status
command shows the following:
To Action From
-- ------ ----
3306 DENY Anywhere
3306 ALLOW 10.0.0.0/8
3306 ALLOW 10.0.0.0/24
3306 (v6) DENY Anywhere (v6)
full ifconfig
looks as follows:
$ ifconfig
ens2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.64.30.117 netmask 255.255.255.254 broadcast 10.64.30.117
inet6 2001:xxxx:xxxx:xxx::1 prefixlen 127 scopeid 0x0<global>
inet6 fe80::dc1c:3cff:fe32:203b prefixlen 64 scopeid 0x20<link>
ether de:1c:3c:32:20:3b txqueuelen 1000 (Ethernet)
RX packets 363358 bytes 1082623290 (1.0 GB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 310592 bytes 37970748 (37.9 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 2844 bytes 779466 (779.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2844 bytes 779466 (779.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
NOTE: These private IPs can change and hence I cannot hardcode them.
Is there any other way to set it in UFW or iptables?
ufw
rules so that DENY is after an acceptable ALLOW rule? You should also only need to ALLOW 10.0.0.0/8 as 10.0.0.0/24 is included in the /8. – GracefulRestart Apr 04 '19 at 00:07