LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-09-2021, 08:22 AM   #1
sulq
LQ Newbie
 
Registered: Sep 2021
Posts: 3

Rep: Reputation: Disabled
Ubuntu Linux - Cannot Access from local host after enable firewall


Hi,
I am a newbie in Linux. I am using Ubuntu Linux 18.04.
I just setup an apache server running at port 80.
I try to access from local machine and from other machines within the same network and it works fine.

Then I try to enable the firewall and it block all the incoming port, so I cannot access from the local machine and from other machines within the network.

Then I add a new rule using ufw to allow from anywhere to access port 80 and check with ufw status.
The new rule is displayed correctly, but it does not work.

Then I add a new rule using iptables:
iptables -A INPUT -p tcp --dport 80 -j ACCEPT

After adding the new rule using iptables, I am able to access from other machine within the same network, but I still CANNOT access the port 80 from my local machine.

Anybody can help?

Thanks,

sulq
 
Old 09-09-2021, 04:51 PM   #2
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,342

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
from the local machine how do you address the web site?

If using localhost then that usually goes to 127.0.0.1:80 and not the network IP. If the web site is not listening on the loopback address it will fail.

Also, are you using only http or also using https? If only http then port 80 is adequate, but if https as well then you need to add port 443 to the firewall rules.
 
Old 09-09-2021, 10:07 PM   #3
sulq
LQ Newbie
 
Registered: Sep 2021
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks computersavvy for your reply.

I am using http (just for testing) and the new rule I put in was:
iptables -A INPUT -p tcp --dport 80 -j ACCEPT

which is actually from anywhere and should the 127.0.0.1 is included?
 
Old 09-10-2021, 03:53 AM   #4
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,791

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
Run
Code:
ss -tulpn | grep :80
or
Code:
sudo lsof -i :80 | grep LISTEN
 
Old 09-10-2021, 04:06 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,294
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
UFW is a front-end for IPtables. So if you are using UFW, stick with that and ignore iptables. And if you are using iptables stick with that and, uninstall UFW. Try something like,

Code:
sudo ufw show added
See "man ufw" for the details and other options.

Myself, since iptables is deprecated, I've moved to nftables. It is far easier than iptables yet more flexible and with more options. Supposedly it is more efficient under the hood, too. So if you are just starting out, I would give serious consideration to taking a step back and begining with nftables instead. Failing that, stick with UFW. Either way, avoid iptables.

https://wiki.nftables.org/

https://wiki.nftables.org/wiki-nftab..._in_10_minutes
 
Old 09-10-2021, 10:03 AM   #6
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,342

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Quote:
Originally Posted by sulq View Post
Thanks computersavvy for your reply.

I am using http (just for testing) and the new rule I put in was:
iptables -A INPUT -p tcp --dport 80 -j ACCEPT

which is actually from anywhere and should the 127.0.0.1 is included?
Yes, & No.

That means the firewall should not block it. However, the config for httpd defines what interfaces it listens to. If it is only listening on the network interface then the loopback interface (127.0.0.1) is ignored.

Check the settings in /etc/httpd/conf/httpd.conf to see what interfaces it listens on.
Code:
$ grep -i listen /etc/httpd/conf/httpd.conf 
# Listen: Allows you to bind Apache to specific IP addresses and/or
# Change this to Listen on specific IP addresses as shown below to 
#Listen 12.34.56.78:80
Listen 80
As you can see I have not bound the httpd daemon to a single interface so it will be listening on all available interfaces.

Running both the commands given by @ferarri gives me
Code:
$ sudo lsof -i :80 | grep LISTEN
[sudo] password for jvian: 
httpd        1461   root    4u  IPv6    33384      0t0  TCP *:http (LISTEN)
httpd     2503157 apache    4u  IPv6    33384      0t0  TCP *:http (LISTEN)
httpd     2503158 apache    4u  IPv6    33384      0t0  TCP *:http (LISTEN)
httpd     2503159 apache    4u  IPv6    33384      0t0  TCP *:http (LISTEN)
httpd     2503160 apache    4u  IPv6    33384      0t0  TCP *:http (LISTEN)
$ 
$ ss -tulpn | grep :80
tcp   LISTEN 0      511                 *:80               *:*
You can see that it is listening on all interfaces, port 80.
 
1 members found this post helpful.
Old 09-11-2021, 10:56 AM   #7
sulq
LQ Newbie
 
Registered: Sep 2021
Posts: 3

Original Poster
Rep: Reputation: Disabled
You are all correct.

The localhost is using the loopback interface.

After adding the below command:
sudo iptables -A INPUT -i lo -j ACCEPT

It works.

Thanks All,

Sulq
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
virtualbox guest cannot access the host's LAN with host-only adapter hortageno Linux - Virtualization and Cloud 3 10-29-2015 11:59 AM
[SOLVED] How to copy file from remote host to local host then delete from remote host legendmac Linux - Newbie 13 05-27-2015 03:47 PM
Cannot ping local systems - but local systems can access internet walterbyrd Linux - Networking 19 07-28-2013 06:23 AM
Please help me setup Local Area Network. I cannot ping Windows XP host from Ubuntu 9 avarashnon Linux - Newbie 1 05-10-2009 07:59 PM
How to enable Outlook Express Mail Checking from Firewall Host wintoe Linux - Networking 3 08-20-2005 08:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration