Saturday, March 19, 2011

Simple Gateway Using ipfw + ipnat


Build A Gateway is a not so difficult. Moreover you have a little

the desire and knowledge about the browser you can easily install the gateway

without facing difficulties.

Many paper or notes about the making of the Gateway router which each has advantages

and lack of variety. On this occasion I present about how making a simple gateways, to handle

a small network.

To build a gateway using IPFW and IPNAT, it is necessary to compile the kernel first

first. Assuming the kernel sources tercopy on location as usual.

indofreebsd # cd / sys/i386/conf

indofreebsd # cp GENERIC INDOFREEBSD

indofreebsd # pico INDOFREEBSD

things are things I edit this section

ident indofreebsd

# options INET6 # I have not felt the need to activate ins.

and add this option

IPFILTER options
IPFILTER_LOG options
IPFIREWALL options
IPFIREWALL_VERBOSE options
IPFIREWALL_VERBOSE_LIMIT options = 5
DUMMYNET options
options HZ = 1000

after editing kernel configuration and I re-compile the kernel.

indofreebsd # cd / usr / src

indofreebsd # make buildkernel KERNCONF = INDOFREEBSD

-------------------------------------------------- ------------
>>> Kernel build for INDOFREEBSD completed on Fri Feb 9 05:57:45 UTC 2007
-------------------------------------------------- ------------


indofreebsd # make installkernel KERNCONF = INDOFREEBSD

install-o root-g wheel-m 555 if_xe.ko / boot / kernel
===> xl (install)
install-o root-g wheel-m 555 if_xl.ko / boot / kernel
===> zlib (install)
install-o root-g wheel-m 555 zlib.ko / boot / kernel
kldxref / boot / kernel

indofreebsd #

input after a few parameters that we need in rc.conf

router_flags = "-q"
router = "/ sbin / routed"
router_enable = "YES"
gateway_enable = "YES"
sendmail_enable = "NONE"
firewall_enable = "YES"
firewall_script = "/ etc / ipfw.rules"
ipnat_enable = "YES" # Start ipnat function
ipnat_rules = "/ etc / ipnat.rules" # rules definition file for ipnat

then save

indofreebsd #
for ipfw rules

indofreebsd # pico / etc / ipfw.rules

################ Start of IPFW rules file ############################# # #
# Flush out the list before We begin.
ipfw-q-f flush

ipfw pipe 1 config mask dst-ip 0x000000ff bw 256Kbit / s
ipfw pipe 2 config mask src-ip 0x000000ff bw 64Kbit / s
ipfw add 1 pipe 1 all from any to 192.168.1.0/24 in
ipfw add 2 pipe 2 all from 192.168.1.0/24 to any out
# Set rules command prefix
cmd = "ipfw-q add"
PIF = "rl0" # public interface name of NIC
# Facing the public Internet

################################################## ###############
# No restrictions on Inside LAN Interface for private network
# Not needed unless you have a LAN.
# Change xl0 to your LAN NIC interface name
################################################## ###############
$ Cmd 00008 allow all from any to any via rl1
################################################## ###############
# No restrictions on Loopback Interface
################################################## ###############
$ Cmd 00010 allow all from any to any via lo0

################################################## ###############
# Allow the packet through if it has been added to the previous
# The "dynamic" rules table by a allow keep-state statement.
################################################## ###############
$ Cmd 00015 check-state

################################################## ###############
# Interface facing Public Internet (Outbound Section)
# Interrogate session start requests originating from behind the
# Firewall on the private network or from this gateway server
# Destine for the public Internet.
################################################## ###############

# Get the IP addresses from / etc / resolv.conf file
$ Cmd 00114 allow tcp from any to any 53 out via $ PIF setup keep-state
$ Cmd 00115 allow udp from any to any 53 out via $ PIF the keep-state
$ Cmd 00122 allow tcp from any to any 21 out via $ PIF setup keep-state
# Allow out non-secure standard www function
$ Cmd 00200 allow tcp from any to any 80 out via $ PIF setup keep-state

# Allow out secure www function https over TLS SSL
$ Cmd 00220 allow tcp from any to any 443 out via $ PIF setup keep-state

# Allow out send & get email function
$ Cmd 00230 allow tcp from any to any 25 out via $ PIF setup keep-state
$ Cmd 00231 allow tcp from any to any 110 out via $ PIF setup keep-state

# Allow out FBSD (make install & cvsup) functions
# Basically give user root "GOD" privileges.
$ Cmd 00240 allow tcp from me to any out via $ PIF setup uid root keep-state

# Allow out ping
$ Cmd 00250 allow icmp from any to any out via $ PIF the keep-state
$ Cmd 00251 allow udp from any to any 33434-33523
# Allow out Time
$ Cmd 00260 allow tcp from any to any 37 out via $ PIF setup keep-state

# Allow out NNTP news (i.e. news groups)
$ Cmd 00270 allow tcp from any to any out via $ PIF 460-30000 setup keep-state

# Allow out secure FTP, Telnet, and SCP
# This function is using SSH (secure shell)
$ Cmd 00280 allow tcp from any to any 22 out via $ PIF setup keep-state

# Allow out whois
$ Cmd 00290 allow tcp from any to any 43 out via $ PIF setup keep-state

# Deny and log everything else that.s Trying to get out.
$ Cmd 00299 deny log all from any to any out via $ PIF

################################################## ###############
# Interface facing Public Internet (Inbound Section)
# Interrogate packets originating from the public Internet
# Destine for this gateway server or the private network.
################################################## ###############

# Deny all inbound traffic from non-routable reserved address spaces
$ Cmd 00300 deny all from 192.168.0.0/16 to any in via $ PIF # RFC 1918 private IP
$ Cmd 00301 deny all from 172.16.0.0/12 to any in via $ PIF # RFC 1918 private IP
$ Cmd 00302 deny all from 10.0.0.0 / 8 to any in via $ PIF # RFC 1918 private IP
$ Cmd 00303 deny all from 127.0.0.0 / 8 to any in via $ PIF # loopback
$ Cmd 00304 deny all from 0.0.0.0 / 8 to any in via $ PIF # loopback
$ Cmd 00305 deny all from 169.254.0.0/16 to any in via $ PIF # DHCP auto-config
$ Cmd 00306 deny all from 192.0.2.0/24 to any in via $ PIF # reserved for docs
$ Cmd 00307 deny all from 204.152.64.0/23 to any in via $ PIF # Sun cluster interconnect
$ Cmd 00308 deny all from 224.0.0.0 / 3 to any in via $ PIF # Class D & E multicast
$ Cmd 00309 allow icmp from any to any icmptypes 11 in
########### Allow me to ping out and receive response back
$ Cmd 00311 allow icmp from any to any icmptypes 0 in.
# Deny public pings
# $ Cmd 00312 deny icmp from any to any in via $ PIF

# Deny all netbios service. 137 = name, 138 = datagram, 139 = session
# Netbios is MS / Windows sharing services.
# Block MS / Windows hosts2 name server requests 81
$ Cmd 00320 deny tcp from any to any 137 in via $ PIF
$ Cmd 00321 deny tcp from any to any 138 in via $ PIF
$ Cmd 00322 deny tcp from any to any 139 in via $ PIF
$ Cmd 00323 deny tcp from any to any 81 in via $ PIF

# Deny any late arriving packets
$ Cmd 00330 deny all from any to any frag in via $ PIF

# Deny ACK packets That did not match the dynamic rule table
$ Cmd 00332 deny tcp from any to any established in via $ PIF
# Allow traffic in from ISP's DHCP server. This rule must contain
# The IP address of your DHCP server as it.s ISP.s the only
# Authorized source to send this packet type.
# Only Necessary for cable or DSL configurations.
# This rule is not needed for. User ppp. type of connection to
# The public Internet. This is the Same IP address you captured
# And Used in the outbound section.
# $ Cmd 00360 allow udp from any to xxxx 67 in via $ PIF the keep-state
$ Cmd 00361 allow tcp from any to any 1023-7000 in via $ PIF setup limit src-addr 2

# Allow in standard www function Because I have apache server
$ Cmd 00400 allow tcp from any to me 80 in via $ PIF setup limit src-addr 2

# Allow in secure FTP, Telnet, and SCP from public Internet
# $ Cmd 00410 allow tcp from any to me 22 in via $ PIF setup limit src-addr 2
$ Cmd 00410 allow tcp from any to me 222 in via $ PIF setup limit src-addr 2
# Allow in non-secure Telnet session from public Internet
# Labeled non-secure Because ID & PW are passed over public
# Internet as clear text.
# Delete this sample group if you do not have telnet server enabled.
$ Cmd 00420 allow tcp from any to me 113 in via $ PIF setup limit src-addr 2

# Reject & Log all incoming connections from the outside
$ Cmd 00499 deny log all from any to any in via $ PIF

# Everything else is denied by default
# Deny and log all packets That Fell through to see what They are
$ Cmd 00999 deny log all from any to any
################ End of IPFW rules file ############################# # #
indofreebsd #

make ipnat.rules

indofreebsd # pico / etc / ipnat.rules

# ------------------------------------------------- -----------
# Use ipfilter FTP proxy for the firewall is doing the transfer mode
# active.
# ------------------------------------------------- -----------
map rl0 0.0.0.0 / 0 -> 0.0.0.0/32 proxy port ftp ftp / tcp
# ------------------------------------------------- -----------
# Use ipfilter FTP proxy for the hosts behind NAT doing transfers
# mode active.
# ------------------------------------------------- -----------
map rl0 192.168.0.0/24 -> 0.0.0.0/32 proxy port ftp ftp / tcp
# ------------------------------------------------- ----------
# Map all UDP and TCP traffic internal to the external IP address
# ------------------------------------------------- ----------
map rl0 192.168.0.0/24 -> 0.0.0.0/32 portmap tcp / udp 40000:60000
# ------------------------------------------------- ----------
# Map all other traffic e.g. ICMP to the external IP address
# ------------------------------------------------- ----------
map rl0 192.168.0.0/24 -> 0.0.0.0/32

then save

His next step is to restart its

indofreebsd # reboot

Test your gateway to connecting client on the gateway pc

if packet does not succeed in that means you miss less rigorous.

thus making steps gateway using ipfw + ipnat

good luck.



greetings,

ogeb

0 comments: