TransWikia.com

My port is closed,even after port forwarding

Ask Ubuntu Asked by Shivank Anchal on February 21, 2021

I am running Apache2 on Ubuntu 20.04 and my server is accessible from all the devices connected to my WIFI router (including phones,and laptops).This is the what is rendered when my server is accessed.
Now I want to access my server from Internet.

This is the output of route -n

frozenmafia@frozenmafia-H81M-S:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    600    0        0 wlxd03745b828ea
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 wlxd03745b828ea
192.168.1.0     0.0.0.0         255.255.255.0   U     600    0        0 wlxd03745b828ea

This is the output of ifconfig

frozenmafia@frozenmafia-H81M-S:~$ ifconfig
enp3s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 40:8d:5c:a5:eb:f9  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        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 5856  bytes 572976 (572.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5856  bytes 572976 (572.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlxd03745b828ea: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.39  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::2970:d411:fb39:7ff6  prefixlen 64  scopeid 0x20<link>
        ether d0:37:45:b8:28:ea  txqueuelen 1000  (Ethernet)
        RX packets 388866  bytes 507534243 (507.5 MB)
        RX errors 0  dropped 2905  overruns 0  frame 0
        TX packets 263147  bytes 67686494 (67.6 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

This is the output of ufw status

frozenmafia@frozenmafia-H81M-S:~$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
Apache Full                ALLOW       Anywhere                  
8080                       ALLOW       Anywhere                  
80/tcp                     ALLOW       Anywhere                  
Apache Full (v6)           ALLOW       Anywhere (v6)             
8080 (v6)                  ALLOW       Anywhere (v6)             
80/tcp (v6)                ALLOW       Anywhere (v6)   

This is the output of sudo netstat -tlpn

frozenmafia@frozenmafia-H81M-S:~$ sudo netstat -tlpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      706/systemd-resolve 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      975/sshd: /usr/sbin 
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      938/cupsd           
tcp        0      0 0.0.0.0:445             0.0.0.0:*               LISTEN      2201/smbd           
tcp        0      0 0.0.0.0:139             0.0.0.0:*               LISTEN      2201/smbd           
tcp6       0      0 :::80                   :::*                    LISTEN      1045/apache2        
tcp6       0      0 :::22                   :::*                    LISTEN      975/sshd: /usr/sbin 
tcp6       0      0 ::1:631                 :::*                    LISTEN      938/cupsd           
tcp6       0      0 :::445                  :::*                    LISTEN      2201/smbd           
tcp6       0      0 :::139                  :::*                    LISTEN      2201/smbd    

To make my machine public I need to do port forwarding.For that I would be configuring my WIFI router.
I did it like this.

This is my WAN status

I believed that this should be enough to make my machine public.I tested it here.It is showing that my port is closed.

Now, I thought of using iptables to do port forwarding.I followed this tutorial
and entered the following commands.

frozenmafia@frozenmafia-H81M-S:~$ cat /proc/sys/net/ipv4/conf/wlxd03745b828ea/forwarding 
1
frozenmafia@frozenmafia-H81M-S:~$ sudo  iptables -t nat -A PREROUTING -p tcp -i wlxd03745b828ea --dport 80 -j DNAT --to-destination 192.168.1.39:80
frozenmafia@frozenmafia-H81M-S:~$ sudo iptables -A FORWARD -p tcp -d 192.168.1.39 --dport 80 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
frozenmafia@frozenmafia-H81M-S:~$ ip route
default via 192.168.1.1 dev wlxd03745b828ea proto dhcp metric 600 
169.254.0.0/16 dev wlxd03745b828ea scope link metric 1000 
192.168.1.0/24 dev wlxd03745b828ea proto kernel scope link src 192.168.1.39 metric 600 

Now,I believe that I have tried everything to make my server public.I again tested my machine accessibility here which shows my failure.

I have contacted my ISP and confirmed that all ports are open.I hope I have explained and substantiated everything I did.It would be great if anyone corrects me and provide me a solution to my problem.
Thanking you

One Answer

As @FedonKadifeli, mentioned that I have a CGNAT.To make my server public I followed this used ngork.Now I and my friends are able to access my webpage.

Correct answer by Shivank Anchal on February 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP