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 - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 04-26-2010, 01:57 AM   #1
brunoskrebs
LQ Newbie
 
Registered: Sep 2007
Posts: 10

Rep: Reputation: 0
apt-get and iptables


Hi there,

I am encountering problems to configure my firewall (through iptables) to allow apt-get features, like update and install.

I have the latest debian server running in a virtual machine in my windows xp and therefore I have two interfaces in this debian server:

- NAT Interface
inet: 10.0.2.15

- Host Only Interface
inet: 192.168.56.101

So far my iptable rules drop all packets for default, in exception icmp and ssh that I allow to ping and connect from my windows xp. Both of them I use only the Host interface (192...) to connect to another 192... interface on my windows. Those are working fine, but apt is not. I know, in this very moment it shouldn't. But I made a lot of attempts trying to configure the iptables allow connections through the 80 and 21 ports from/to NAT and Host. I think I made all possible combination (or not, because it didnt work). But I'm wondering if someone more experient can help me solve this problem...

Thanks in advance,
Bruno Krebs.
 
Old 04-26-2010, 02:32 AM   #2
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by brunoskrebs View Post
Hi there,

I am encountering problems to configure my firewall (through iptables) to allow apt-get features, like update and install.

I have the latest debian server running in a virtual machine in my windows xp and therefore I have two interfaces in this debian server:

- NAT Interface
inet: 10.0.2.15

- Host Only Interface
inet: 192.168.56.101

So far my iptable rules drop all packets for default, in exception icmp and ssh that I allow to ping and connect from my windows xp. Both of them I use only the Host interface (192...) to connect to another 192... interface on my windows. Those are working fine, but apt is not. I know, in this very moment it shouldn't. But I made a lot of attempts trying to configure the iptables allow connections through the 80 and 21 ports from/to NAT and Host. I think I made all possible combination (or not, because it didnt work). But I'm wondering if someone more experient can help me solve this problem...

Thanks in advance,
Bruno Krebs.


Can we see a your rules??
 
Old 04-26-2010, 02:41 AM   #3
ddaemonunics
Member
 
Registered: May 2008
Location: Romania
Distribution: Debian
Posts: 242

Rep: Reputation: 41
take a look at iptables --state ESTABLISHED,RELATED,NEW
 
Old 04-26-2010, 05:38 AM   #4
SuperJediWombat!
Member
 
Registered: Apr 2009
Location: Perth, Australia
Distribution: Ubuntu/CentOS
Posts: 208

Rep: Reputation: 51
Your question is not very clear, we need more information to help you.

Can you post the output of:
Code:
iptables-save
ifconfig
Are you sure that it is iptables causing the issues?
try disabling iptables and see if the issue is sill there.

If disabling iptables does not fix the issue, post the output of:
Code:
cat /etc/apt/sources.list

Last edited by SuperJediWombat!; 04-26-2010 at 05:40 AM.
 
Old 04-26-2010, 11:40 AM   #5
brunoskrebs
LQ Newbie
 
Registered: Sep 2007
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by SuperJediWombat! View Post
Your question is not very clear, we need more information to help you.

Can you post the output of:
Code:
iptables-save
ifconfig
Are you sure that it is iptables causing the issues?
try disabling iptables and see if the issue is sill there.

If disabling iptables does not fix the issue, post the output of:
Code:
cat /etc/apt/sources.list
Well yes, I'm sure it iptables causing the issue (my rules actually), because when I reset the iptables rules to accept everything, I can use apt features normally.

So I'm going to post everything here now (ifconfig, rules and source.list):

ifconfig
Code:
eth0      Link encap:Ethernet  HWaddr 08:00:27:2d:77:26  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe2d:7726/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:16 errors:0 dropped:0 overruns:0 frame:0
          TX packets:19 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:3094 (3.0 KiB)  TX bytes:2166 (2.1 KiB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:6c:8d:78  
          inet addr:192.168.56.101  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe6c:8d78/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:27 errors:0 dropped:0 overruns:0 frame:0
          TX packets:33 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2398 (2.3 KiB)  TX bytes:3047 (2.9 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:560 (560.0 B)  TX bytes:560 (560.0 B)
rules
Code:
# Generated by iptables-save v1.4.2 on Mon Apr 26 10:27:16 2010
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT DROP [0:0]
-A INPUT -s 192.168.56.1/32 -d 192.168.56.101/32 -p icmp -j ACCEPT 
-A INPUT -s 192.168.56.1/32 -d 192.168.56.101/32 -p tcp -m tcp --dport 22 -j ACCEPT 
-A OUTPUT -s 192.168.56.101/32 -d 192.168.56.1/32 -p icmp -j ACCEPT 
-A OUTPUT -s 192.168.56.101/32 -d 192.168.56.1/32 -p tcp -m tcp --dport 22 -j ACCEPT 
COMMIT
# Completed on Mon Apr 26 10:27:16 2010
source.list
Code:
# regular update for lenny
deb http://ftp.br.debian.org/debian/ lenny main contrib
deb-src http://ftp.br.debian.org/debian/ lenny main contrib

# security updates for lenny
deb http://security.debian.org/ lenny/updates main contrib
deb-src http://security.debian.org/ lenny/updates main contrib

# volatile
deb http://volatile.debian.org/debian-volatile lenny/volatile main contrib
deb-src http://volatile.debian.org/debian-volatile lenny/volatile main contrib
I know that those rules wont let me connect to ports 21 and 80, the ones that I saw it is used by apt. But like I said before I made a lot of combinations allowing from/to 192.168.56.101 to everywhere, even from/to 10.0.2.15 from/to everywhere on ports 21 and 80, but it dindt work. I was unable to update, search and install using apt-get with all these attempts...

With this information, what rules should I use to allow apt features to workd, I mean in a secure way, because I'm using this virtualbox to be like a mirror from my real server that I'm supposed to take real good care of the firewall...

Thanks again!
 
Old 04-27-2010, 01:11 AM   #6
ddaemonunics
Member
 
Registered: May 2008
Location: Romania
Distribution: Debian
Posts: 242

Rep: Reputation: 41
from your rules...you block all OUTGOING traffic(except ssh to one destination), how do you aspect it to work..
you should at least allow outgoing traffic to ftp.br.debian.org port 80 and use the bottom rule with -m state.
Also you should allow loopback traffic, outgoing dns queries(--dport 53 -p udp) , incoming dns replies(--sport 53 -p udp) ( -m state ESTABLISHED,RELATED will solve that)

iptables -A INPUT -i ethX -m state --state ESTABLISHED,RELATED -j ACCEPT will allow incoming traffic related to your outgoing connections.
please read a tutorial on linux firewall ...it might help you

Last edited by ddaemonunics; 04-27-2010 at 01:15 AM.
 
Old 04-27-2010, 01:56 AM   #7
SuperJediWombat!
Member
 
Registered: Apr 2009
Location: Perth, Australia
Distribution: Ubuntu/CentOS
Posts: 208

Rep: Reputation: 51
As ddaemonunics said, you need to allow more traffic through. This would be a start...

Code:
# Generated by SuperJediWombat's iptables configurator of awesome.
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT DROP [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A OUTPUT -p udp --dport 53 -j ACCEPT
-A OUTPUT -p tcp --dport 21 -d ftp.br.debian.org -j ACCEPT
-A OUTPUT -p tcp --dport 21 -d security.debian.org -j ACCEPT
-A OUTPUT -p tcp --dport 21 -d volatile.debian.org -j ACCEPT
-A OUTPUT -p tcp --dport 80 -d ftp.br.debian.org -j ACCEPT
-A OUTPUT -p tcp --dport 80 -d security.debian.org -j ACCEPT
-A OUTPUT -p tcp --dport 80 -d volatile.debian.org -j ACCEPT
-A OUTPUT -s 192.168.56.101/32 -d 192.168.56.1/32 -p icmp -j ACCEPT 
-A OUTPUT -s 192.168.56.101/32 -d 192.168.56.1/32 -p tcp -m tcp --dport 22 -j ACCEPT 
COMMIT
Keep in mind that iptables will attempt to do the DNS lookup for those domains when you add the rule set, and the IP may change. Also if you are having DNS issues, it obviously will not work.
 
Old 04-27-2010, 02:00 AM   #8
brunoskrebs
LQ Newbie
 
Registered: Sep 2007
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ddaemonunics View Post
from your rules...you block all OUTGOING traffic(except ssh to one destination), how do you aspect it to work..
you should at least allow outgoing traffic to ftp.br.debian.org port 80 and use the bottom rule with -m state.
Also you should allow loopback traffic, outgoing dns queries(--dport 53 -p udp) , incoming dns replies(--sport 53 -p udp) ( -m state ESTABLISHED,RELATED will solve that)

iptables -A INPUT -i ethX -m state --state ESTABLISHED,RELATED -j ACCEPT will allow incoming traffic related to your outgoing connections.
please read a tutorial on linux firewall ...it might help you
Thanks for your, reply, I will study a bit more about these established and related connections...

Oh and by the way, I was expecting it to work, because, like I said in my previous post, I made A LOT off attempts like allowing INPUT and OUTPUT packets on both ports 80 and 21 with different sources and destinations... I just didn't put them here because they didn't work and because I made a really lot of different combinations...
 
Old 04-27-2010, 02:05 AM   #9
brunoskrebs
LQ Newbie
 
Registered: Sep 2007
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by SuperJediWombat! View Post
As ddaemonunics said, you need to allow more traffic through. This would be a start...

Code:
# Generated by SuperJediWombat's iptables configurator of awesome.
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT DROP [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A OUTPUT -p udp --dport 53 -j ACCEPT
-A OUTPUT -p tcp --dport 21 -d ftp.br.debian.org -j ACCEPT
-A OUTPUT -p tcp --dport 21 -d security.debian.org -j ACCEPT
-A OUTPUT -p tcp --dport 21 -d volatile.debian.org -j ACCEPT
-A OUTPUT -p tcp --dport 80 -d ftp.br.debian.org -j ACCEPT
-A OUTPUT -p tcp --dport 80 -d security.debian.org -j ACCEPT
-A OUTPUT -p tcp --dport 80 -d volatile.debian.org -j ACCEPT
-A OUTPUT -s 192.168.56.101/32 -d 192.168.56.1/32 -p icmp -j ACCEPT 
-A OUTPUT -s 192.168.56.101/32 -d 192.168.56.1/32 -p tcp -m tcp --dport 22 -j ACCEPT 
COMMIT
Keep in mind that iptables will attempt to do the DNS lookup for those domains when you add the rule set, and the IP may change. Also if you are having DNS issues, it obviously will not work.

Thanks for your reply too, very enlightening I would say. Just to be sure, if someone send a ESTABLISHED packet to my server that my server was not expecting it wouldnt be stupid to accept this unexpected packet right?
 
Old 04-27-2010, 02:12 AM   #10
SuperJediWombat!
Member
 
Registered: Apr 2009
Location: Perth, Australia
Distribution: Ubuntu/CentOS
Posts: 208

Rep: Reputation: 51
No, every packet falls into either ESTABLISHED, RELATED, NEW or INVALID. A packet that was claiming to be part of an existing connection, would be INVALID if it was not recorded by the connection tracker.

The reason your earlier attempts probably failed is that you did not allow DNS traffic through, and your computer could not have resolved the IP addresses of the Debian apt servers.
 
Old 04-27-2010, 02:28 AM   #11
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
What you should also always do is log blocked/dropped packets.
Very good for troubleshooting
 
Old 04-27-2010, 10:26 AM   #12
brunoskrebs
LQ Newbie
 
Registered: Sep 2007
Posts: 10

Original Poster
Rep: Reputation: 0
Guys, thank you very much for your help, everything is working now! And yes, probablye the problem was that I was not allowing DNS traffic through.
 
  


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 giving troubles with APT-Get, WGet, etc Emil M Linux - Software 3 02-25-2010 01:52 AM
LXer: Create a Local Ubuntu Repository using Apt-Mirror and Apt-Cacher LXer Syndicated Linux News 0 08-04-2009 10:13 PM
apt pinning /etc/apt/apt.conf parent's_basement Debian 5 10-26-2008 05:50 PM
iptables v1.2.9: Unknown arg `/sbin/iptables' Try `iptables -h' or 'iptables --help' Niceman2005 Linux - Security 4 12-29-2005 08:20 PM
apt-get update errors since Debian released ( bad /etc/apt/sources.list ?) forgox Debian 10 06-13-2005 12:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 01:41 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