rt2400/NAT

Stara konfiguracja ( 2005r. - 2006r. ) gdy miałem kartę wifi Ralink a mój komputer pracował pod Gentoo jako router.

____802.1d Bridge i konfiguracja LAN____

włączenie obsługi Ethernet Bridging w jądrze 2.6
opcje oznaczone [*] zostały wkompilowane w kernel,
oznaczone [x] skompilowano jako moduly

Networking options
	[*] 802.1d Ethernet Bridging

Instalacja pakietu narzędzi niezbędnych do zarządzania mostkiem:

emerge bridge-utils

konfiguracja br0 w pliku /etc/conf.d/net

# To add ports to bridge br0
bridge_br0="eth0 eth1"
# You need to configure the ports to null values
# so dhcp does not get started
config_eth0=( "null" )
config_eth1=( "null" )
# Finally give the bridge an address - dhcp or a static IP]
# config_br0=( "dhcp" )
config_br0=( "192.168.0.1 netmask 255.255.255.0" )
ln -sf /etc/init.d/net.lo /etc/init.d/net.eth1
rc-update add net.eth0 default
rc-update add net.eth1 default
/etc/init.d/net.br0 start

tworzymy dowiązania między net.lo i net.eth1,
urządzenie sieciowe dodajemy do domyślnych skryptów startowych i
uruchmiamy interfejs br0

ln -sf /etc/init.d/net.lo /etc/init.d/net.eth1
rc-update add net.eth0 default
rc-update add net.eth1 default
/etc/init.d/net.br0 start

______rt2400 i konfiguracja WAN______

strona ze sterownikami do karty znajdowala sie pod linkiem http://rt2x00.serialmonkey.com/wiki/index.php/Downloads obecnie sterowniki wchodzą w skład pakietu linux-wireless.

tar -xzf rt2400-*.tar.gz
cd Module
make
make install

echo alias ra0 rt2400 > /etc/modules.d/rt2400
modules-update

podajemy adresy serwerów DNS w pliku /etc/resolv.conf

nameserver 194.204.152.34
nameserver 194.204.159.1
domain net

konfiguracja interfejsu ra0

cd /etc/init.d
ln -sf net.eth0 net.ra0

edytujemy /etc/conf.d/net i podajemy dane sieci wifi

mode_ra0="managed"
essid_ra0="WTL_MARC"
key_WTL_MARC="c0XXxxXXxx enc open"

modules=("iwconfig")
config_ra0=("192.168.1.41 netmask 255.255.255.0")
routes_ra0=("default gw 192.168.1.1")

startujemy kartę i dodajemy do domyślnych skryptów startowych

rc-update add net.ra0 default
/etc/init.d/net.ra0 start

______ustawiamy DHCP dla sieci LAN______

instalacja serwera

emerge dnsmasq

edytujemy pliki konfiguracyjne /etc/dnsmasq.conf

dhcp-range=192.168.0.100,192.168.0.250,72h

i /etc/conf.d/dnsmasq

trzeba dodac "-i br0" do DNSMASQ_OPTS

uruchamiamy usługę

rc-update add dnsmasq default
/etc/init.d/dnsmasq start

______routing______

założenia
br0 --> LAN
ra0 --> WAN
siec LAN 192.168.0.xx
router 192.168.0.1

konfiguracja jądra 2.6

Networking options
	[*] TCP/IP networking
		[*] IP: advanced router
	[*] Network packet filtering (replaces ipchains)
If you use 2.4.x, you have to enable the following for DHCP:
	[*] Socket Filtering

	IP: Netfilter Configuration  --->
		[*] Connection tracking (required for masq/NAT)
			[x] FTP protocol support
			[x] IRC protocol support
		[*] IP tables support (required for filtering/masq/NAT)
			[*] IP range match support
			[x] MAC address match support
			[*] Multiple port match support
		[*] Packet filtering
			[*] REJECT target support
			[x] REDIRECT target support
		[*] Full NAT
			[*] MASQUERADE target support
		[x] LOG target support

instalacja i konfiguracja iptables

emerge iptables

iptables -F
iptables -t nat -F

iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP

export LAN=br0
export WAN=ra0

iptables -I INPUT 1 -i ${LAN} -j ACCEPT
iptables -I INPUT 1 -i lo -j ACCEPT
iptables -A INPUT -p UDP --dport bootps -i ! ${LAN} -j REJECT
iptables -A INPUT -p UDP --dport domain -i ! ${LAN} -j REJECT

iptables -A INPUT -p TCP --dport ssh -i ${WAN} -j ACCEPT

iptables -A INPUT -p TCP -i ! ${LAN} -d 0/0 --dport 0:1023 -j DROP
iptables -A INPUT -p UDP -i ! ${LAN} -d 0/0 --dport 0:1023 -j DROP

iptables -I FORWARD -i ${LAN} -d 192.168.0.0/255.255.0.0 -j DROP
iptables -A FORWARD -i ${LAN} -s 192.168.0.0/255.255.0.0 -j ACCEPT
iptables -A FORWARD -i ${WAN} -d 192.168.0.0/255.255.0.0 -j ACCEPT
iptables -t nat -A POSTROUTING -o ${WAN} -j MASQUERADE

uruchomienie forwardingu

echo 1 > /proc/sys/net/ipv4/ip_forward
for f in /proc/sys/net/ipv4/conf/*/rp_filter ; do echo 1 > $f ; done

/etc/init.d/iptables save
rc-update add iptables default

edytujemy /etc/sysctl.conf

net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 1