Score:0

IPtables shows the Port number but unable to access site from remote machine on same network

tg flag

/etc/systables/iptables has the following line

-A INPUT -p tcp -m tcp --dport 4000 -j ACCEPT

I tried

sudo service iptables save
sudo service iptables restart

the above did not open the port when I try from the browser on remote machine on the same network. however, netstat shows the port:

$ netstat -ano|grep 4000
tcp        0      0 127.0.0.1:4000          127.0.0.1:33956         FIN_WAIT2   timewait (24.83/0/0)
tcp        1      0 127.0.0.1:33956         127.0.0.1:4000          CLOSE_WAIT  keepalive (4.78/0/0)
tcp        1      0 127.0.0.1:33930         127.0.0.1:4000          CLOSE_WAIT  keepalive (8.95/0/0)
tcp        1      0 127.0.0.1:33934         127.0.0.1:4000          CLOSE_WAIT  keepalive (8.96/0/0)
tcp        0      0 127.0.0.1:4000          127.0.0.1:33930         FIN_WAIT2   timewait (23.99/0/0)
tcp        0      0 127.0.0.1:4000          127.0.0.1:33934         FIN_WAIT2   timewait (24.00/0/0)
tcp        0      0 127.0.0.1:4000          127.0.0.1:33946         FIN_WAIT2   timewait (24.70/0/0)
tcp        1      0 127.0.0.1:33946         127.0.0.1:4000          CLOSE_WAIT  keepalive (3.44/0/0)

Port 3000 is already open, but it is not even in /etc/sysconfig/iptables. Where else would it be? How can I repeat the same steps to open 4000?

$ netstat -ano|grep 3000
tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      off (0.00/0/0)
tcp        0      0 xx.xx.xx.xx:3000     xxx.xx.xxx.xxx:60784    ESTABLISHED off (0.00/0/0)
tcp        0      0 xx.xx.xx.xxx:3000     xxx.xx.xxx.147:59742    ESTABLISHED off (0.00/0/0)
jp flag
You have nothing listening on port 4000. If you want to access some service on port 4000, you need to configure this service to run and listen on port 4000.
Tims avatar
tg flag
Isn't iptables the appropriate tool to configure the port?
jp flag
`iptables` is a network filter which allows or denies access to a port, but you still need some service to listen on the port.
Tims avatar
tg flag
well, reactjs is listening on 4000 and django is listening on 9000.
jp flag
your `netstat` output shows that there is nothing listening on port 4000.
Ginnungagap avatar
gu flag
`netstat` was replaced by `ss` for some time now. In any case `-tlpn` would list all listening TCP ports and their associated programs.
HBruijn avatar
in flag
*"Isn't iptables the appropriate tool to configure the port?"* No. Not quite. The server application is where you configure on which port and network interface/IP-address it should create and bind a TCP/UDP socket / listener to accept incoming connections. `iptables` is used to configure a host based firewall and can be used to block or allow access to that listener, but doesn't create that listener. i.e. iptables can used to allow access to TCP port 80, but without a web server that will accept and respond to requests that come in on port 80, your browser will get a connection refused error
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.