NAT and Firewall

From AsIsWiki
Jump to: navigation, search
Форум

FreeBSD


NAT and Firewall

Создаем копию файла конфигурации ядра:

# cd /sys/i386/conf
# cp GENERIC NAT

Добавляем в файл конфигурации NAT следующие строки:

machine	i386
#cpu		I486_CPU
cpu		I586_CPU
cpu		I686_CPU
ident		NAT
maxusers	100

...

options 	ADAPTIVE_GIANT		# Giant mutex is adaptive.

options		IPFIREWALL
options		IPFILTER
options		IPDIVERT
options		IPFIREWALL_VERBOSE
options		IPFIREWALL_VERBOSE_LIMIT=100

device		apic			# I/O APIC

Конфигурируем новое ядро:

# config NAT
Kernel build directory is ../compile/NAT
Don't forget to do make clean depend; make depend

Собираем ядро с новой конфигурацией:

# cd ../compile/NAT
# make depend 
# make clean 
# make all 
# make install 
# reboot 

Редактируем файл загрузки /etc/rc.conf:

defaultrouter="195.80.252.33"

gateway_enable="YES"

hostname="gate.asistech.org"

network_interfaces="xl0 rl0 lo0"

ifconfig_xl0="inet 195.80.252.37  netmask 255.255.255.224"

ifconfig_rl0="inet 192.168.0.1  netmask 255.255.255.0"

#keymap="ru.koi8-r"

natd_enable="YES"

linux_enable="YES"

sshd_enable="YES"

Проверяем конфигурацию /etc/hosts:

::1			localhost.asistech.org localhost
127.0.0.1		localhost.asistech.org localhost
195.80.252.37		gate.asistech.org gate
195.80.252.37		gate.asistech.org.

Создаем файл /etc/resolv.conf:

domain		asistech.org
nameserver	195.80.252.2
nameserver	195.80.253.2

Создаем файл с правилами NATD/IPFW /usr/local/etc/rc.d/firewall.sh:

#!/bin/sh

/sbin/ipfw -q -f flush
/sbin/ipfw -q add pass all from any to any via lo0
/sbin/ipfw -q add deny all from any to 127.0.0.0/8
/sbin/ipfw -q add deny all from 127.0.0.0/8 to any

# divert
/sbin/ipfw -q add divert natd ip from 192.168.0.0/24 to any out via xl0
/sbin/ipfw -q add divert natd ip from any to 195.80.252.37 in via xl0

# open ping
/sbin/ipfw -q add pass icmp from any to any

# close telnet from outdoor
/sbin/ipfw -q add reset tcp from any to 195.80.252.37 23 in via xl0

# open ftp, ssh, smtp, pop3, http
/sbin/ipfw -q add pass tcp from any to any 20,21,22,25,110,80,8080
/sbin/ipfw -q add pass tcp from any 20,21,22,25,110,80,8080 to any

# open https
# YahooMessenger=5050
# icq=5190
/sbin/ipfw -q add pass tcp from any to any 119,443,5050,5190
/sbin/ipfw -q add pass tcp from any 119,443,5050,5190 to any

# open dns
/sbin/ipfw -q add pass udp from any to any 53,123
/sbin/ipfw -q add pass udp from any 53,123 to any
/sbin/ipfw -q add pass all from any to any via rl0

Создаем файл запуска демона NATD /usr/local/etc/rc.d/natd.sh:

#!/bin/sh 
/sbin/natd -f /etc/natd.conf -n xl0 

Делаем файлы исполняемыми:

# chmod +x firewall.sh 
# chmod +x natd.sh 

Создаем файл конфигурации демона NATD /etc/natd.conf:

same_ports yes 
use_sockets yes 

Создаем пользователя (в процессе создания добавляем его в группу wheel):

# adduser john 

С любой машины, используя ssh-клиента проверяем подключение к маршрутизатору:

# ssh john@192.168.0.1



Форум

FreeBSD

Personal tools
Namespaces

Variants
Actions
Navigation
Tools