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 09-09-2004, 03:31 AM   #1
SpaceCowboy
LQ Newbie
 
Registered: Jun 2004
Distribution: Mandrake
Posts: 13

Rep: Reputation: 0
iptables and ip aliases


I run my Mandrake 10 box with this ifconfig

Code:
eth0      Link encap:Ethernet  HWaddr 00:A0:A2:00:D8:5C
          inet addr:10.0.0.10  Bcast:10.0.0.255  Mask:255.255.255.0
          inet6 addr: fe80::2a0:a2ff:fe00:d85c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:124109 errors:0 dropped:0 overruns:0 frame:0
          TX packets:138700 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:41993748 (40.0 Mb)  TX bytes:72004095 (68.6 Mb)
          Interrupt:12 Base address:0x7000

eth0:1    Link encap:Ethernet  HWaddr 00:A0:A2:00:D8:5C
          inet addr:192.168.0.1  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:123572 errors:0 dropped:0 overruns:0 frame:0
          TX packets:137775 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:39174113 (37.3 Mb)  TX bytes:68604205 (65.4 Mb)
          Interrupt:12 Base address:0x7000

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:701 errors:0 dropped:0 overruns:0 frame:0
          TX packets:701 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:147283 (143.8 Kb)  TX bytes:147283 (143.8 Kb)

ppp0      Link encap:Point-to-Point Protocol
          inet addr:80.183.4.33  P-t-P:192.168.100.1  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1492  Metric:1
          RX packets:123572 errors:0 dropped:0 overruns:0 frame:0
          TX packets:137775 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3
          RX bytes:39174113 (37.3 Mb)  TX bytes:68604205 (65.4 Mb)
I use my eth0 to connect my PC to PPP0, and I use eth0:1 to connect Mandrake to a Windows Laptop (IP: 192.168.0.2)

I found this script to enable internet sharing from Mandrake to Windows, and it works well:

Code:
#!/bin/sh
#an iptables rule to enable masquerading:

iptables -t nat -I POSTROUTING -o ppp0 -j MASQUERADE

#enable ip forwarding:

echo 1 > /proc/sys/net/ipv4/ip_forward

# An optional rule to allow the laptop to talk to
# _the desktop for ssh & samba

#windowslaptop
iptables -I INPUT -s 192.168.0.2 -d 192.168.0.1 -j ACCEPT
The question is..

When I try to set a rule like this:


Code:
 iptables -A OUTPUT -o eth0:1 -s 192.168.0.1/24 -d 192.168.0.0/24 -j ACCEPT
I receive this output:

Code:
 Warning: wierd character in interface `eth0:1' (No aliases, :, ! or *).
I don't know very well iptables... Googling around I found iptables doesn't like ip aliases... I looking for a way to write rules without "eth0:1" inside... There's a way to build a firewall/router with this requirements?

1. allow every protocol inside my LAN

2. Protect my LAN from internet.

3. allow my Laptop and my Mandrake BOX to access internet without problem (POP3, FTP, HTTP, P2P)

4. Allow my Mandrake box to accept incoming connection from internet with FTP, HTTP, P2P, WEBMIN etc.


Thank you in advance.

SC
 
Old 09-09-2004, 04:56 AM   #2
maxut
Senior Member
 
Registered: May 2003
Location: istanbul
Distribution: debian - redhat - others
Posts: 1,188

Rep: Reputation: 50
iptables -A OUTPUT -o eth0:1 -s 192.168.0.1/24 -d 192.168.0.0/24 -j ACCEPT
what do u want to do?
it is not necessary to block output chain. it is your local output.

eth0:1 doesnt work here too. i dont know if it is possible to use aliased net devices. u can configure your firewall like this without "eth0:1" :

if u want to share your internet securely. u must do that by FORWARD chain.
iptables -F FORWARD # remove all rules in forward chain
iptables -P FOWARD DROP # assing the default policy to drop for FORWARD chain
iptables -A FORWARD -s 192.168.0.0/24 -j ACCEPT # accpet all packets which come from 192.168.0.0/24 and go to other networks (like internet)
iptables -A FORWARD -s 10.0.0.0/24 -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT # allow all established related packets.

now your local networks behind your firewall is in secure enough.

and if u wanna secure your gateway linux, u must do that by INPUT chain:
iptables -F INPUT
iptables -P INPUT DROP
iptables -A INPUT -d lo -j ACCEPT
iptables -A INPUT -s 192.168.0.0/24 -j ACCPET
iptables -A INPUT -s 10.0.0.0/24 -j ACCPET
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

and open necessary ports comes from ppp0 interface like that:
iptables -A INPUT -i ppp0 -p (protocol) --dport (port_no) -j ACCEPT

u can see the porocols and port numbers of services in /etc/services file.
u can add these iptables rules to your iptables scripts.

good luck

Last edited by maxut; 09-09-2004 at 04:58 AM.
 
Old 09-09-2004, 07:18 AM   #3
SpaceCowboy
LQ Newbie
 
Registered: Jun 2004
Distribution: Mandrake
Posts: 13

Original Poster
Rep: Reputation: 0
Smile Wonderful!!

It works!!! (until now :-)

Only a problem..

iptables doesn't like "lo" interface

Code:
iptables v1.2.9: host/network `lo' not found
So I've changed

Code:
iptables -A INPUT -d lo -j ACCEPT
to

Code:
iptables -A INPUT -d 127.0.0.1/255.0.0.0 -j ACCEPT
Now..my script

Code:
#!/bin/sh
#Firewall/router script.. Thanx to maxut and Linuxquestions.org


# if u want to share your internet securely. u must do that by FORWARD chain.
 
iptables -F FORWARD # remove all rules in forward chain
iptables -P FORWARD DROP # assing the default policy to drop for FORWARD chain
iptables -A FORWARD -s 192.168.0.0/24 -j ACCEPT # accept all which come from your net and go to other net (like internet)
iptables -A FORWARD -s 10.0.0.0/24 -j ACCEPT 
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT # allow all established related packets.
 
#now your local networks behind your firewall is in secure enough. 
 
#and if u wanna secure your gateway linux, u must do that by INPUT chain:

iptables -F INPUT
iptables -P INPUT DROP
iptables -A INPUT -d 127.0.0.1/255.0.0.0 -j ACCEPT
iptables -A INPUT -s 192.168.0.0/24 -j ACCEPT
iptables -A INPUT -s 10.0.0.0/24 -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

#open port:
#rule: iptables -A INPUT -i ppp0 -p (protocol) --dport (port_no) -j ACCEPT

#FTP
iptables -A INPUT -i ppp0 -p tcp --dport 21 -j ACCEPT
#SSH
iptables -A INPUT -i ppp0 -p tcp --dport 22 -j ACCEPT
#SMTP
iptables -A INPUT -i ppp0 -p tcp --dport 25 -j ACCEPT
#HTTP and HTTPS
iptables -A INPUT -i ppp0 -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -i ppp0 -p tcp --dport 443 -j ACCEPT
#POP3
iptables -A INPUT -i ppp0 -p tcp --dport 110 -j ACCEPT
#NTP
iptables -A INPUT -i ppp0 -p tcp --dport 123 -j ACCEPT
#GAIM and C. on M$N
#iptables -A INPUT -i ppp0 -p tcp --dport 1863 -j ACCEPT
#eDonkey-aMule
iptables -A INPUT -i ppp0 -p tcp --dport 4661 -j ACCEPT
iptables -A INPUT -i ppp0 -p tcp --dport 4662 -j ACCEPT
iptables -A INPUT -i ppp0 -p udp --dport 4665 -j ACCEPT
iptables -A INPUT -i ppp0 -p udp --dport 4666 -j ACCEPT
#Webmin
iptables -A INPUT -i ppp0 -p tcp --dport 10000 -j ACCEPT
#FreeDB and CDDB
iptables -A INPUT -i ppp0 -p tcp --dport 888 -j ACCEPT
iptables -A INPUT -i ppp0 -p tcp --dport 8880 -j ACCEPT
#Nicotine/Soulseek
iptables -A INPUT -i ppp0 -p tcp --dport 2234 -j ACCEPT
#DNS
iptables -A INPUT -i ppp0 -p tcp --dport 53 -j ACCEPT

### MASQUERADING ###

# Next, an iptables rule to enable masquerading:

iptables -t nat -I POSTROUTING -o ppp0 -j MASQUERADE

# Finally, enable ip forwarding:

echo 1 > /proc/sys/net/ipv4/ip_forward
I think it's ok now... Any suggestion? What about "lo" interface?

thanks a lot.

SC
 
Old 09-09-2004, 08:02 AM   #4
SpaceCowboy
LQ Newbie
 
Registered: Jun 2004
Distribution: Mandrake
Posts: 13

Original Poster
Rep: Reputation: 0
first Problem...

It seems that I can't connect to my ppp0 address (every protocol fails: FTP, HTTP..etc)

So I think I'm unreachable from internet.. What's gone wrong?

thanx

SC
 
Old 09-09-2004, 07:48 PM   #5
SpaceCowboy
LQ Newbie
 
Registered: Jun 2004
Distribution: Mandrake
Posts: 13

Original Poster
Rep: Reputation: 0
workaround!

I found this workaround:

Code:
iptables -A INPUT -s $EXTIP -j ACCEPT
$EXTIP is obtained with

Code:
EXTIP="`/sbin/ifconfig ppp0 | grep 'inet addr' | awk '{print $2}' | sed -e 's/.*://'`"
If I understand well, This rule allow every INPUT from my external IP (my ppp0 IP)


Now, Another question: Is this rule secure.. Or have I to allow only some protocol?

Thanx!!!

SC

Last edited by SpaceCowboy; 09-09-2004 at 07:50 PM.
 
Old 09-09-2004, 11:29 PM   #6
r_213
Member
 
Registered: Sep 2004
Posts: 36

Rep: Reputation: 15
Can u send the contents of /proc/net/dev of the machine from where u have executed the ifconfig command.

Thank U in advance.
Regrads,
-Ranganathan.
 
Old 09-10-2004, 01:39 AM   #7
maxut
Senior Member
 
Registered: May 2003
Location: istanbul
Distribution: debian - redhat - others
Posts: 1,188

Rep: Reputation: 50
Re: Wonderful!!

Quote:
Originally posted by SpaceCowboy


Only a problem..

iptables doesn't like "lo" interface

Code:
iptables v1.2.9: host/network `lo' not found
So I've changed

Code:
iptables -A INPUT -d lo -j ACCEPT
to

Code:
iptables -A INPUT -d 127.0.0.1/255.0.0.0 -j ACCEPT
sorry, it was my mistake. it should be
Code:
iptables -A INPUT -i lo -j ACCEPT
but your rule (-d 127.0.0.1) is ok too.


u should allow only certain protocols. like this:
iptables -A INPUT -i ppp0 -p tcp --dport 21 -j ACCEPT # do this, if u have a ftp server on gateway box
iptables -A INPUT -i ppp0 -p tcp --dport 80 -j ACCEPT # do this, if u have http server on gateway box

addational info:
if u have a server behind your firewall u can forward that service port.
iptables -t nat -A PREROUTING -i ppp0 -p tcp --dport 80 -j DNAT --to 192.168.0.10
this will forward http packets (tcp 80) to 192.168.0.10 if packets come to ppp0.

also u dont have to type $EXTIP, u can use device name. like ppp0.
and u mustnt use :
iptables -A INPUT -i ppp0 -j ACCEPT
if u do, u will allow everthing comes from external network to gateway box.. it is not recommended.
 
Old 09-14-2004, 04:53 AM   #8
SpaceCowboy
LQ Newbie
 
Registered: Jun 2004
Distribution: Mandrake
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
and u mustnt use :
iptables -A INPUT -i ppp0 -j ACCEPT
if u do, u will allow everthing comes from external network to gateway box.. it is not recommended.
Yes, Ok.. I don't use "-i ppp0" but "-s $EXTIP"

I think it means "accept all packets coming from the source $EXTIP", right?

And when I type iptables -L I found this line about it:

Code:
ACCEPT     all  --  host100-11.pool8000.myserver.com  anywhere
I don't know why, but I can't connect to myself using my no-ip account (if I type ftp://myaccount.no-ip.com from my mandrakeBox), without this rule!! (But FROM OUTSIDE I think all is ok, I tested my firewall using https://grc.com/x/ne.dll?bh0bkyd2 )

Thank you all!

SC
 
Old 09-14-2004, 07:17 AM   #9
maxut
Senior Member
 
Registered: May 2003
Location: istanbul
Distribution: debian - redhat - others
Posts: 1,188

Rep: Reputation: 50
Quote:
Originally posted by SpaceCowboy
Yes, Ok.. I don't use "-i ppp0" but "-s $EXTIP"

I think it means "accept all packets coming from the source $EXTIP", right?

surely u r right.
 
Old 09-14-2004, 11:03 AM   #10
SpaceCowboy
LQ Newbie
 
Registered: Jun 2004
Distribution: Mandrake
Posts: 13

Original Poster
Rep: Reputation: 0
Talking uh?

uh? Ok .. I'm right!

Thanks a lot!

SC
 
  


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, Multiple IP Aliases and Different Rules for each external ip genmud Linux - Networking 7 09-18-2005 02:07 AM
Aliases SkyeFyre Fedora 8 03-18-2005 07:35 PM
using aliases after doing su? NonSumPisces Linux - Newbie 2 08-15-2004 02:19 PM
aliases depaul Linux - Software 23 07-30-2003 06:49 PM
what aliases do you use most? m0rl0ck Linux - General 17 02-12-2003 01:25 AM

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

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