使用Linux系統(tǒng)架設(shè)安全的網(wǎng)關(guān) |
發(fā)布時(shí)間: 2012/8/11 10:38:47 |
1、網(wǎng)關(guān)主機(jī)設(shè)置
服務(wù)器上有兩塊網(wǎng)卡,eth0使用*.*.*.*IP地址連接Internet,eth1連接LAN,則其/etc/network/interfaces的設(shè)置如下: 以下為引用的內(nèi)容: auto lo iface lo inet loopback auto eth0 iface eth0 inet static address *.*.*.* netmask 255.255.255.0 gateway *.*.*.254 auto eth1 iface eth1 inet static address 192.168.0.1 network 192.168.0.0 netmask 255.255.255.0 broadcast 192.168.0.255 當(dāng)然也可以使用ifconfig進(jìn)行配置: $ ifconfig eth0 *.*.*.* netmask 255.255.255.0 $ route add default gw *.*.*.254 $ ifconfig eth1 192.168.0.1 netmask 255.255.255.0 dns在/etc/resolv.conf中設(shè)置,修改或添加nameserver字段: nameserver 202.120.2.101 如果ip地址是與mac綁定的,還要修改mac地址: $ ifconfig eth0 down $ ifconfig eth0 hw ether *:*:*:*:*:* $ ifconfig eth0 up
這時(shí)將lan內(nèi)主機(jī)網(wǎng)關(guān)改為192.168.0.1,應(yīng)該能ping通該網(wǎng)關(guān),但是還是連不上internet。要實(shí)現(xiàn)LAN內(nèi)的機(jī)器通過共享一個(gè)單獨(dú)的可訪問外網(wǎng)的IP地址來訪問Internet資源,還需要在網(wǎng)關(guān)上安裝ipmasq。 以下為引用的內(nèi)容:
3、端口映射 假設(shè)lan內(nèi)有一ftp192.168.0.2,要從internet上訪問該ftp,需要在網(wǎng)關(guān)主機(jī)上進(jìn)行一定的端口映射?墒褂胕ptables完成。下面是具體實(shí)現(xiàn)的腳本例子: 以下為引用的內(nèi)容: /sbin/modprobe iptable_filter /sbin/modprobe ip_tables /sbin/modprobe iptable_nat /sbin/modprobe ip_nat_ftp /sbin/modprobe ip_conntrack /sbin/modprobe ip_conntrack_ftp iptables -F iptables -P INPUT ACCEPT iptables -P FORWARD ACCEPT iptables -P OUTPUT ACCEPT iptables -F -t nat iptables -t nat -A PREROUTING -p tcp -i eth0 -d 202.120.2.101 --dport 21 -j DNAT --to 192.168.123.6:21 iptables -t nat -A PREROUTING -p tcp -i eth0 -d 202.120.2.101 --dport 2345 -j DNAT --to 192.168.123.116:3389 iptables -t nat -A POSTROUTING -s 192.168.123.0/24 -o eth0 -j SNAT --to 202.120.16.34 echo 1 > /proc/sys/net/ipv4/ip_forward 本文出自:億恩科技【www.allwellnessguide.com】 服務(wù)器租用/服務(wù)器托管中國(guó)五強(qiáng)!虛擬主機(jī)域名注冊(cè)頂級(jí)提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM] |