LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 02-24-2018, 08:18 PM   #1
sniper8752
Member
 
Registered: Oct 2012
Posts: 564

Rep: Reputation: Disabled
iptables rule setup


I am trying to allow web server traffic from internal only. When I do this:

Code:
sudo iptables -I INPUT -p tcp -s eth1 -m multiport --dports 80,443 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
I get this error:

Code:
iptables vx: host/network `eth1' not found
eth1 = lan interface on server. Referring to the man pages for iptables:

Quote:
Source specification. Address can be either a network name, a hostname, a network IP address
Isn't this a network name?

Also, is this rule the best way of accomplishing this?
 
Old 02-24-2018, 08:22 PM   #2
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
Network name doesn't mean interface name. It simply means that you can specify a mask. For instance, 10.0.0.0/24. -i (in) or -o (out) work with interface names - depending on how the data flows.
 
Old 02-24-2018, 08:25 PM   #3
sniper8752
Member
 
Registered: Oct 2012
Posts: 564

Original Poster
Rep: Reputation: Disabled
With IP spoofing, is there a more secure way of doing this?
 
Old 02-24-2018, 08:28 PM   #4
sniper8752
Member
 
Registered: Oct 2012
Posts: 564

Original Poster
Rep: Reputation: Disabled
I tried the -o option, and it said: Can't use -o with INPUT
 
Old 02-24-2018, 08:29 PM   #5
sniper8752
Member
 
Registered: Oct 2012
Posts: 564

Original Poster
Rep: Reputation: Disabled
It would go from internal interface (eth1) to wan interface (eth0). Let me know if this helps.
 
Old 02-24-2018, 08:34 PM   #6
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
Please don't write a post for each idea you're coming up with. Just edit the initial post or wait for the answer. You've already stated three different things.

INPUT chains refers only to packets received by the server itself. You don't use INPUT if you want your machine to act as a router (forwarding packets), which you seem to imply in your last post. So what are you trying to do exactly? Is this a web server that you'd like to access only from your LAN? If that's the case, then I don't understand what you mean by going from internal to wan. It should be only internal and that's that.

INPUT only works with -i, because you're receiving packets through an interface. OUTPUT goes with -o.
 
Old 02-24-2018, 08:42 PM   #7
sniper8752
Member
 
Registered: Oct 2012
Posts: 564

Original Poster
Rep: Reputation: Disabled
Sorry.

I have pi hole listening on the wan interface, but maybe I should change that to lan, and this would be easier/make more sense?
 
Old 02-24-2018, 08:48 PM   #8
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
I've no idea what pi hole is. I just did a quick search on the internet - some advertisment stuff. How would anyone know where you'd like it to listen? WAN is internet, LAN is your private network. You're jumping from one thing to another and you haven't reacted to either of my posts and you probably haven't tried anything after my suggestions.
 
Old 02-24-2018, 08:57 PM   #9
sniper8752
Member
 
Registered: Oct 2012
Posts: 564

Original Poster
Rep: Reputation: Disabled
You are correct in saying that I'd like to access it only from my lan. What would be the iptable rule to allow it to respond only to local requests?
 
Old 02-24-2018, 09:06 PM   #10
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
Having quickly read (again) about pi hole, I understand that it works as a DNS server which filters ads by simply dropping packets from ad servers (kind of like OpenDNS). This has nothing to do with allowing ports 80, 443 in iptables. The only thing you need to do is to allow udp, tcp port 53 in lan (which I'm guessing is already allowed, but to answer your question, yes, allow it on LAN, not WAN - unless you're looking to access it from the internet, which I doubt) and then set up your computers to use the pi hole as the DNS server. Then it should works directly. Ideally, you could simply add the pi-hole ip on your dhcp server (probably included in your home router) as the single DNS server used by your network devices, so that you don't need to manually configure each - especially the phones which would be somewhat harder and annoying to do.
 
Old 02-24-2018, 09:09 PM   #11
sniper8752
Member
 
Registered: Oct 2012
Posts: 564

Original Poster
Rep: Reputation: Disabled
The reason for 80/443 is the admin/gui/stats interface website that it provides. I've tried adding this rule:
Code:
sudo iptables -I INPUT -p tcp -i eth1 -m multiport --dports 80,443 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
But the website loads not only internally, but also on my wan external IP, which is NOT what I want.
 
Old 02-24-2018, 09:11 PM   #12
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
What is the output of iptables -vnL INPUT?
 
Old 02-24-2018, 09:16 PM   #13
sniper8752
Member
 
Registered: Oct 2012
Posts: 564

Original Poster
Rep: Reputation: Disabled
Code:
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
 x  x ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0
x   x ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
Do you believe it is another rule, in addition to the rule, that is causing the external ip to load the webpage?
 
Old 02-24-2018, 09:22 PM   #14
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
Well I would strongly suggest at least learning the basics of iptables. For instance, here: https://www.digitalocean.com/communi...s-and-commands
The rule you're trying to add doesn't have much of an impact, because you're already allowing everything. You should either change your INPUT policy to DROP, or add an explicit reject/drop rule at the end of your chain. You might also want to add ssh access (at least from the LAN?) to it. So you'd need udp/tcp 53 and tcp 22, 80, 443.
 
Old 02-24-2018, 09:27 PM   #15
sniper8752
Member
 
Registered: Oct 2012
Posts: 564

Original Poster
Rep: Reputation: Disabled
Do other chains need an explicit reject/drop rule at the end as well?
 
  


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
Iptables rule help linuxcenter Linux - Security 3 06-26-2013 06:21 AM
iptables rule amartlk Linux - Security 1 01-25-2012 01:55 AM
iptables: rule with RETURN target just after a rule with ACCEPT target Nerox Linux - Networking 6 09-04-2011 03:33 PM
iptables rule kim_bcs Linux - Security 1 01-28-2011 09:34 AM
What is it doing this iptables rule?? lanczer Linux - Security 1 02-24-2006 11:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 05:49 PM.

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