FreeBSD FireWall Using IP Filter Via PPPoe

xiaoxiao2021-03-06  96

U n i x c i r c l e

FreeBSD FireWall Using IP Filter Via PPPoe

By Hoang Q. TRAN

IT is real simple to build freebsd gateway for a private network. You Only Need to do several tasks. Details Are Given Below.

Lock Down The Box Setup Network Interfaces Customize The Kernel Network Tunings PPPoe Firewall Configure Machines Behind Nat Familiarize with ipfilter Reference

Lock down the boxThe first step in setting up a firewall is to disable any unused services. This helps minimize potential local and remote exploits. Edit /etc/rc.conf and make sure inetd, portmap, sendmail daemons are all disabled.

inetd_enable = "no"

Sendmail_enable = "none"

Check_quotas = "no"

If you don't need Remote Logon, make sure sshd_enable = "no".

Once you disabled unnecessary services, go to unixcircle.com portscan to remotely port scan your own box from the outside. Be careful when you do this behind a NAT / firewall box as the port scan script will scan the NAT / firewall instead. If you Have Another Box, Use nmap to scan the box from the inside.

Get the Latest FreeBSD Security Patches Manually and Apply Them from Here:

ftp://ftp.freebsd.org/pub/freebsd/cert/patches/

OR USE CVSUP TO

Synchronize The Stable Release and Build.

For More Information On Security Vulnerabilities, Read Sans The Twenty Most Critical Internet Security VulneRabilities (Updated)

Setup network interfacesAssume this box has 2 3com 509B network cards and their FreeBSD driver are named as ep0 and ep1 for first and second card. First network card will use the non-routable private address according to rfc1918. The second will be assigned either static or Dynamic Via DHCP IP Address.

Non-Routable IP Addresses for Private Networks: 10.0.0.1 - 10.255.255.254 Netmask 255.0.0.0

172.16.0.1 - 172.31.255.254 Netmask 255.240.0.0

192.168.0.1 - 192.168.255.254 Netmask 255.255.0.0

Assume You Choose 192.168.0.1 Range, Enable The First Network Interface in /etc/rc.conf:

ifconfig_ep0 = "inet 192.168.1.1 Netmask 255.255.255.0"

Customize the KernelTo Compile The New Kernel You NEED The Kernel Source (Part of Kernel Developer Distribution). If you have. '' '' '' '' '

# CD / SYS / I386 / CONF

I usually name the kenel to the machine hostname, but you can give it. Edit The Kernel Config File:

# cp generic firewall

# vi firewall

In The Options Section, Add these Lines for PPPOE:

Options netgraph

Options Netgraph_ETHER

Options netgraph_pppoe

Options netgraph_socket

FireWall and Nat:

Options ipfilter # ipfilter support

Options ipfilter_log # ipfilter logging support

Options ipfilter_default_block # block all packets by Default

Options random_ip_id # random_ip_id causes the ID Field in ip packets to be randomized

# instead of increment by 1 with Each packet generated.

Remove any hardware related `` options '' that are not relevant to your machine. One way to find out what to keep is to consult the dmesg output and remove all the rest. For all available kernel options, refer to LINT in the same directory As The Kernel File. Save The Kernel Config File and The Compile and Install IT:

# CD / USR / SRC

# Make Buildkernel Kernconf = Firewall

(keilding Output ...)

...

# make installkernel kernconf = firewall

# rebootthis will retain the old kernel as /kernel.old Just in case Something Has Gone awry with the new one and the box doesn't boot. if That happens you can type 'kernel.old' at the boot: prompt to boot Old kernel.

Network tuningsadd the folload to /etc/sysctl.conf:

To enable packet forwarding:

Net.inet.ip.Forwarding = 1

To Verify That An Incoming Packet ARRIVES ON ANTERFACE THAT AN Address Matching The Packet's Destination Address:

Net.inet.ip.check_interface = 1

To Drop Syn Packets Destine to Non-Listening TCP / UDP Port. This Will Create A Blackhole and Protect Against Stealth Port Scans:

Net.inet.tcp.blackhole = 2

Net.inet.udp.blackhole = 1

TO Enable High Performance Data TransferS on Hosts According To

Enabling High Performance Data Transfers:

# 1. Path MTU Discovery: enabled by Default

# 2. TCP EXTENSION (RFC1323): Enabled by Default

# 3. Increase TCP Window Size for Increase In Network Performance

Net.inet.tcp.recvspace = 65535

Net.inet.tcp.sendspace = 65535

# 4. Sack (RFC2018): FreeBSD Doesn't Have A Sack Implementation

PPPoe

And if you receive your public address assignment via pppoe, edit /etc/rc.conf and add:

ifconfig_ep1 = "INET 0.0.0.0 MTU 1492"

ifconfig_ep1 = "INET 10.0.0.1 Netmask 255.255.255.0"

PPP_ENABLE = "YES"

PPP_nat = "no"

PPP_MODE = "DDIAL"

PPP_Profile = "Myisp"

Here is a working /etc/ppp/ppp.conf:

DEFAULT:

SET log Phase Chat LCP IPCP CCP TUN COMMAND

Set Redial 15 28800

Set reconnect 15 28800

Myisp:

SET log Phase Chat LCP IPCP CCP TUN COMMAND

Set Device PPPoe: EP1

Set authname xxxyoursecretnamexxx

Set authkey xxxyoursecretkeyxxx

SET MRU 1492

Set MTU 1492

SET CD 5Set Speed ​​Sync

Set Redial 15 28800

Set reconnect 15 28800

Disable LQR

Set Timeout 120

SET IFADDR 10.0.0.1/0 10.0.0.2/0 255.255.255.0 0.0.0.0

Add Default Hisaddr

Firewall

Filter rule:

Since You Don't Know What To Block Yet, You NEED To Open Up Ingress and Outgress Traffic To Flow Through. Edit /etc/ipf.rules and add:

Pass in all

Pass Out All

Network address translation rule:

For Nat and Ftp Clients Behind Nat To Work, Add The Following To /etc/ipnat.rules:

Use ipfilter ftp proxy for ftp client transfers mode: ACTIVE

Map tun0 192.168.1.0/24 -> 0.0.0.0/32 proxy port ftp ftp / tcp

Map all tcp and udp connections from 192.168.1.0/24 to external ip address

Map tun0 192.168.1.0/24 -> 0.0.0.0/32 portmap TCP / UDP 40000: 60000

For all other ip packets, map to the external ip address

Map tun0 192.168.1.0/24 -> 0.0.0.0/32

Make Sure All the `proxy 'Lines Are Before Any Generic` Portmap' Lines, as The First Match Always Wins.

TO Enable FireWall and Nat on bootup, add the folowing to /etc/rc.conf:

ipfilter_enable = "yes" #stateful firewall

IPNAT_ENABLE = "YES" #Network Address TraSlation

IPFS_ENABLE = "YES" #enable saving and reasoning state tables between reboot

IPMON_ENABLE = "YES" #firewall logging

IPMON_FLAGS = "- DSN"

-D: Cause IPMON to Turn Itself Into a daem.

-n: IP Addresses and Port Numbers Will Be mapped, WHERE POSSIBLE, Back Into Hostnames and Service Names.

-s: Packet Information Read in Will Be Sent Through syslogd rather Than Saved to a file.

Configure machines behind NATAll the machines on the private network should be configured to use the address of the private interface of the FreeBSD box as the default gateway.To set the internal boxes to the default FreeBSD gateway on various operating systems:

Assume the FreeBSD Box Nat / Firewall Has IP Address: 192.168.1.1

AIX: edit /etc/rc.net and add / usr / sbin / route add 192.168.1.1 Gateway >> $ logfile 2> & 1

Freebsd: edit /etc/rc.conf and add defaultrouter = "192.168.1.1"

HP-UX: Edit /etc/rc.config.d/netconf and add route_gateway [0] = "192.168.1.1"

Linux redhat: edit / etc / sysconfig / network and add gateway = 192.168.1.1

NetBSD: Echo "192.168.1.1"> / etc / mygate

OpenBSD: Echo "192.168.1.1"> / etc / mygate

Solaris: Echo "192.168.1.1"> / etc / defaultrouter

Win2k: start-settings-> control panel-> network and dial-up connections-> local area network->

Properties-> Internet Protocol (TCP / IP) -> Default Gateway-> 192.168.1.1

IF you don't want to reboot to pick up the ip address for the default gateway, use `` Route '' to manually add the default route.

AIX: Route Add 0 192.168.1.1

HP-UX: Route Add 192.168.1.1

FreeBSD, NetBSD, OpenBSD, Solaris: Route Add Default 192.168.1.1

Linux Redhat: Route Add Default GW 192.168.1.1

2. /etc/resolv.conf on Unix Client Hosts Need To Edit / Add to Have Nameserver Statements in Order To Resolve Hostnames.

UNIX Clients:

$ CAT /ETC/Resolv.conf

Nameserver

Nameserver

Win2k:

Start-settings-> Control Panel-> Network and Dial-Up Connections-> local area network->

Properties-> Internet Protocol (TCP / IP) -> -> Advanced TCP / IP Settings-> DNSAND Add The ISP DNS IPS.

Familiarize with ipfilteronce your nat / firewall is online, you shouth

IP filter howto and add more blocking / passing rules to /etc/ipf.rules. Some Other Useful Links Can Also Be Found ON

IP filter home page. Each time /etc/ipf.rules or /etc/ipnat.rules is modified, you need to flush the rules as:

# / sbin / ipf -fa -f /etc/ipf.rules

# / sbin / ipnat -cf -f -f /etc/ipnat.rules

You can use ipfstat to display firewall statistics a la `` TOP "Command:

# / sbin / ipfstat -t

FireWall.Muine.org - IP Filter: V3.4.29 - State Top 23:01:10

SRC = 0.0.0.0 DEST = 0.0.0.0 proto = any sorted by = # bytes

Source IP Destination IP St Pr #PKTS #BYTES TTL

192.168.1.200, 1415 65.92.100.89, 6699 4/4 TCP 8245 6923504 42:14:06

23.234.234.2, 24064 208.31.160.30, 22 4/4 TCP 576 199843 119: 59: 59

192.168.1.200, 2091 64.124.41.191,8888 4/4 TCP 157 118770 51:36:40

192.168.1.200, 1094 64.124.41.161,8888 4/4 TCP 125 94190 46:37:34

To Find Out The IPfilter Version:

# / sbin / ipf -v

IPF: IP Filter: V3.4.29 (264)

KERNEL: IP Filter: V3.4.29

Running: YES

Log Flags: 0 = none set

Default: Block All, Logging: Available

Active List: 0

Notice the `` block all "setting from ouboptions ipfilter_default_block in the kernel.

To Display THE CURRENT LIST OF Active Map / Redirect Filters and Active Sessions:

# / sbin / ipnat -l

To Find Out The `` Hit "Statistic for Each Individual Rule in /etc/ipf.rules:

# / sbin / ipfstat -hio

See Also ipftest (1), Mkfilters (1), IPF (4), IPL (4), IPF (8), IPFSTAT (8), IPMON (8), IPNAT (8) for Details.Reference

Ipfilter Home Page:

http://www.ipfilter.org

Ipfilter How-to:

http://www.unixcircle.com/ipf/

Address Allocation for Private Internets:

http://www.muine.org/rfc/rfc1918.txt

The IP Network Address Translator (NAT):

http://www.muine.org/rfc/rfc1631.txt

Traditional IP Network Address Translator (Traditional NAT)

http://www.muine.org/rfc/rfc3022.txt

The TWENTY MOST CRITICILIT Security VulneRabilities (Updated)

http://66.129.1.101/top20.htm

Last Update: July 27, 2003

Copyright © 2000-2003 Unixcircle

Contact Webmaster@unixcircle.com

转载请注明原文地址:https://www.9cbs.com/read-105233.html

New Post(0)