[BSD] ipfw + nat

Pagina: 1
Acties:

  • Lagune
  • Registratie: Juli 2001
  • Laatst online: 17-08 20:54

Lagune

Its time for warp

Topicstarter
Ik heb een simpel firewalletje gemaakt , echter als ik die divert regel laad doet nat het niet :(

Zie ik iets over het hoofd ? of staan mijn regels in een verkeerde volgorde?

add divert natd all from any to any via rl1
add allow ip from 127.0.0.1 to 127.0.0.1 via lo0
add deny ip from 127.0.0.1 to any
add deny ip from any to 127.0.0.1
add deny ip from 192.168.0.0/16 to any
add deny ip from any to 192.168.0.0/16
add deny ip from 172.16.0.0/12 to any
add deny ip from any to 172.16.0.0/12
add allow udp from any to any 53,123 keep-state out
add 0601 allow all from 10.16.0.0/12 to any
add deny icmp from any to <public-IP>
add allow icmp from any to any keep-state
add check-state
add deny tcp from any to any established
add allow tcp from any to any keep-state out setup
add allow tcp from any 20 to any keep-state in setup
add allow tcp from any to any 22,23,80,113 keep-state in setup
add 00800 allow all from 10.16.0.0 to any out
add 00900 allow all from any to any via dc0
add deny log logamount 0 ip from any to any

  • Lagune
  • Registratie: Juli 2001
  • Laatst online: 17-08 20:54

Lagune

Its time for warp

Topicstarter
rc.conf :
ipnat_enable="YES"
ipnat_rules="/etc/ipnat.rules"

natd_enable="YES"
natd_interface="rl1"
natd_flags="-f /etc/natd.conf"

----------------------
natd.conf

interface rl1
use_sockets yes
same_ports yes
dynamic yes

  • Leon
  • Registratie: Maart 2000
  • Laatst online: 15-08 14:12

Leon

Rise Of The Robots

Lees ik het nou goed en heb je EN ipnat EN ook nog natd aan staan :?

Ik weet niet wat voor BSD je gebruikt (dat staat niet in je openingspost) maar ik neem maar even aan dat het FreeBSD is (vanwege ipnat + natd).

FreeBSD heeft 2 firewalls (ipfirewall en ipfilter). Ipfirewall bestuur je met het user-space programmaatje "ipfw" en ipfilter met "ipf". (verwarrend, ik weet het)

Elk van deze 2 firewalls heeft een eigen nat methode. Ipfirewall gebruikt natd, en ipfilter ipnat.

(Ipfirewall) natd werkt in user-space.
(Ipfilter) ipnat werkt in kernel space.

Dus voor het natten zou ik ipnat liever gebruiken omdat het (ietsje) sneller is, en omdat je met ipfs na een schone reboot de state tables weer gewoon kunt herladen (Al je ssh, ftp, irc, etc verbindingen blijven (als de time-out lang genoeg is) bewaard).

Nu denk ik dat je ze allebei een beetje door elkaar haalt.

[ Voor 47% gewijzigd door Leon op 13-07-2003 02:01 ]

Eeuwige n00b


  • epias
  • Registratie: Februari 2001
  • Niet online
Leon schreef op 13 July 2003 @ 01:03:
(Ipfirewall) natd werken allebei in user-space.
Alleen natd toch? Staat zo wel in het handboek:
IPFW, the software supplied with FreeBSD, is a packet filtering and accounting system which resides in the kernel, and has a user-land control utility, ipfw. Together, they allow you to define and query the rules used by the kernel in its routing decisions.

  • Leon
  • Registratie: Maart 2000
  • Laatst online: 15-08 14:12

Leon

Rise Of The Robots

epias schreef op 13 July 2003 @ 01:20:
[...]
Alleen natd toch? Staat zo wel in het handboek:

[...]
Voor de duidelijkheid, ik bedoelde dus dat natd in userland werkt en ipnat in kernel land :)

Ik had er eerst staan: "Ipfirewall + natd werken ...". Maar dat kwam verkeerd over (omdat ik wist dat alleen natd in userland werkt en ipfw niet), dus heb ik het aangepast en de bijbehordende firewall (ipfirewall en ipfilter) er tussen haakjes bijgezet. Helaas vergeten de rest te editten..

[ Voor 50% gewijzigd door Leon op 13-07-2003 02:25 ]

Eeuwige n00b


  • Lagune
  • Registratie: Juli 2001
  • Laatst online: 17-08 20:54

Lagune

Its time for warp

Topicstarter
userland & kernel land ???

het gekke is dat ipnat + rc.firewall open (ipfw) werkt , zonder natd , ga ik natd alleen gebruiken -> no go
ga ik beide gebruiken -> no go

Ik snap natd.conf niet , dit heb ik als ipnat.rules , hoe converteer ik dat naar natd.conf ?

map rl1 10.16.0.30/24 -> 0/32 portmap tcp/udp auto
map rl1 10.16.0.30/24 -> 0/32

alvast bedankt

  • JeroenT
  • Registratie: Juli 2001
  • Laatst online: 15-08 20:32

JeroenT

hoi!

Ok , ik zal even mijn cfg's neerzetten zodat je iig een router functioneel hebt ;

/etc/ipnat.rules:

code:
1
2
3
4
5
6
7
8
9
10
map dc0 192.168.1.0/24 -> 0/32 proxy port ftp ftp/tcp
map dc0 192.168.1.0/24 -> 0/32 portmap tcp/udp auto
map dc0 192.168.1.0/24 -> 0/32

# Squid redirecting transparant proxy
rdr tl0 0/0 port 80 -> 127.0.0.1 port 3128 tcp  
#deze rule zou ik niet aanzetten als je geen squid hebt draaien

# VNC portmap 
rdr dc0 0.0.0.0/0 port 4489 -> 192.168.1.35 port 4489 tcp/udp


/etc/ipf.rules:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
###################################
# Outside Interface dc0  
###################################
# loopback pakets left unmolested
pass in quick on lo0 all
pass out quick on lo0 all
#----------------------------------------------------------------
# Allow out all TCP. UDP. and ICMP traffic & keep state on it
# so that it's allowed back in.
#----------------------------------------------------------------
pass out quick on dc0 proto tcp from any to any keep state
pass out quick on dc0 proto udp from any to any keep state
pass out quick on dc0 proto icmp from any to any keep state
block out quick on dc0 all

# block incoming/outgoing unroutable addresses on interface ex1
block in quick on dc0 from 192.168.0.0/16 to any
block in quick on dc0 from 172.16.0.0/12 to any
block in quick on dc0 from 127.0.0.0/8 to any
block in quick on dc0 from 10.0.0.0/8 to any
block in quick on dc0 from 169.254.0.0/16 to any
block in quick on dc0 from 192.0.2.0/24 to any
block in quick on dc0 from 204.152.64.0/23 to any
block in quick on dc0 from 224.0.0.0/3 to any
block in quick on dc0 from 255.255.255.255/32 to any
block in quick on dc0 from 0.0.0.0/32 to any
block out quick on dc0 from any to 192.168.0.0/16
block out quick on dc0 from any to 172.16.0.0/12
block out quick on dc0 from any to 127.0.0.0/8
block out quick on dc0 from any to 10.0.0.0/8
block out quick on dc0 from any to 169.254.0.0/16
block out quick on dc0 from any to 192.0.2.0/24
block out quick on dc0 from any to 204.152.64.0/23
block out quick on dc0 from any to 224.0.0.0/3
block out quick on dc0 from any to 255.255.255.255/32
block out quick on dc0 from any to 0.0.0.0/32

# drop any IP packets with options set in them
block in quick all with ipopts
block in quick all with frag
block in quick all with short
block return-rst in quick proto tcp all flags FUP

# SSH
pass in quick on dc0 proto tcp from any to any port = 22 flags S keep state

# Apache Webserver
pass in quick proto tcp from any to any port = 80  flags S keep state

# FTP
pass in quick proto tcp from any to any port = 21 flags S keep state

# VPN
pass in quick on tl0 proto gre from any to any keep state
pass in quick on tl0 proto tcp from any to any port = pptp keep state

# Q3 server
pass in quick proto udp from any to any port = 27960 

# To receive traceroute replies
pass in quick on dc0 proto icmp from any to any icmp-type timex keep state
pass in quick on dc0 proto icmp from any to any icmp-type echorep

# Outbound traffic from our own IPs is allowed
# Could be made more strict for icmp
pass out quick on dc0 proto tcp/udp from 217.120.170.235/32 to any
pass out quick on dc0 proto tcp/udp from 217.120.170.235/24 to any
pass out quick on dc0 proto icmp from 217.120.170.235/32 to any
pass out quick on dc0 proto icmp from 192.168.1.0/24 to any

# Block and log all remaining traffic coming into the firewall
block return-rst in log quick on dc0 proto tcp from any to any
block return-icmp-as-dest(port-unr) in log quick on dc0 proto udp from any to any
block in log quick on dc0 all

###################################
# Inside Interface tl0
###################################
#----------------------------------------------------------------
# Allow out all TCP. UDP. and ICMP traffic & keep state
#----------------------------------------------------------------
pass out quick on tl0 proto tcp from any to any
pass out quick on tl0 proto udp from any to any
pass out quick on tl0 proto icmp from any to any

#----------------------------------------------------------------
# Allow in all TCP. UDP. and ICMP traffic & keep state
#----------------------------------------------------------------
pass in quick on tl0 proto tcp from any to any
pass in quick on tl0 proto udp from any to any
pass in quick on tl0 proto icmp from any to any


en dan in je /etc/rc.conf:

code:
1
2
3
4
5
6
7
8
9
10
11
ipfilter_enable="YES"
ipnat_enable="YES"

# Volgende regels gebruik ik voor traffic shapen. zijn niet nodig voor ipf en ipnat.

#natd_enable="YES"

#firewall_enable="YES"
#firewall_script="/etc/rc.dummynet"
#firewall_type="open"
#firewall_logging="YES"


Verander alle dc0's voor je externe interface en alle tl0's voor je interne ;)

[ Voor 16% gewijzigd door JeroenT op 13-07-2003 13:20 ]


  • Lagune
  • Registratie: Juli 2001
  • Laatst online: 17-08 20:54

Lagune

Its time for warp

Topicstarter
dit ziet er leuk uit maar dit is ipfilter , ik gebruik ipfw , op de een of andere manier lukt het niet met ipfilter

ben nu ff nieuwe kernel aan het bakken met ipfilter , maybe that works :)

Begint me iig wel wat duidelijker te worden

ipfw/natd of ipf/ipnat dus

[ Voor 41% gewijzigd door Lagune op 13-07-2003 14:24 ]


  • Lagune
  • Registratie: Juli 2001
  • Laatst online: 17-08 20:54

Lagune

Its time for warp

Topicstarter
hij werkt !! YES , ipfilter roels! (thanks klubbheads)

zonder dit werkte het trouwens niet (rc.conf) :
ipfilter_rules="/etc/ipf.rules"

[ Voor 25% gewijzigd door Lagune op 13-07-2003 16:26 ]


  • epias
  • Registratie: Februari 2001
  • Niet online
Als je bovenstaande ipfilter rules gebruikt, zet dan wel
'options IPFILTER_DEFAULT_BLOCK' in je kernel config.

Of plaats deze twee regels aan het begin van je ipf rules:

block in all
block out all
Pagina: 1