NAT DHCP WWW rc.local
来源:互联网 发布:外汇数据行情做单 编辑:程序博客网 时间:2024/05/18 01:56
/***** 外网访问内网的主机,可以在内网主机搭建WWW服务器让外网访问;内网主机既可以动态获取IP访问外网,也可以手动设置IP访问外网!
一,搭建NAT服务器实现内网与外网相互访问;
二,搭建DHCP服务器便于对内网主机网络参数的管理;
三,在内网主机上搭建WWW服务器(这里是在"192.168.1.80"主机上);
以下是具体实现过程:
(eth1为外网接口,etho为内网接口) *****/
/***** 在/bin下新建nat.sh,内容如下: *****/
/***** nat.sh *****/
#!/bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward
#echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
#echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
#INET_IF="ppp0"
INET_IF="eth1"
LAN_IF="eth0"
INET_IP="218.198.18.56" #(根据具体网络环境设定)
WWW_IP="192.168.1.80" #(搭建www服务器的内网主机)
LAN_IP_RANGE="192.168.1.0/24"
IPT="/sbin/iptables"
TC="/sbin/tc"
MODPROBE="/sbin/modprobe"
$MODPROBE ip_tables
$MODPROBE iptable_nat
$MODPROBE ip_nat_ftp
$MODPROBE ip_nat_irc
$MODPROBE ipt_mark
$MODPROBE ip_conntrack
$MODPROBE ip_conntrack_ftp
$MODPROBE ip_conntrack_irc
$MODPROBE ipt_MASQUERADE
for TABLE in filter nat mangle ; do
$IPT -t $TABLE -F
$IPT -t $TABLE -X
$IPT -t $TABLE -Z
done
$IPT -P INPUT ACCEPT
$IPT -P OUTPUT ACCEPT
$IPT -P FORWARD ACCEPT
$IPT -t nat -P PREROUTING ACCEPT
$IPT -t nat -P OUTPUT ACCEPT
$IPT -t nat -P POSTROUTING ACCEPT
# 拒绝INTERNET客户访问
$IPT -A INPUT -i $INET_IF -m state --state RELATED,ESTABLISHED -j ACCEPT
#$IPT -A INPUT -i $INET_IF -p tcp -s 123.5.0.0/16 --dport 22 -j ACCEPT
#$IPT -A INPUT -i $INET_IF -p tcp --dport 80 -j ACCEPT
$IPT -A INPUT -i $LAN_IF -p udp --dport 67 -j ACCEPT
$IPT -A INPUT -i $INET_IF -m state --state NEW,INVALID -j DROP
for DNS in $(grep ^n /etc/resolv.conf|awk '{print $2}'); do
$IPT -A INPUT -p tcp -s $DNS --sport domain -j ACCEPT
$IPT -A INPUT -p udp -s $DNS --sport domain -j ACCEPT
done
# anti bad scaning
$IPT -A INPUT -i $INET_IF -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP
$IPT -A INPUT -i $INET_IF -p tcp --tcp-flags ALL ALL -j DROP
$IPT -A INPUT -i $INET_IF -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
$IPT -A INPUT -i $INET_IF -p tcp --tcp-flags ALL NONE -j DROP
$IPT -A INPUT -i $INET_IF -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
$IPT -A INPUT -i $INET_IF -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
$IPT -t nat -A PREROUTING -d $INET_IP -p tcp --dport 80 -j DNAT --to-destination $WWW_IP:80
#(以上这条规则很重要,实现外网通过80端口访问内网WWW服务器)
if [ $INET_IF = "ppp0" ] ; then
$IPT -t nat -A POSTROUTING -o $INET_IF -s $LAN_IP_RANGE -j MASQUERADE
else
$IPT -t nat -A POSTROUTING -o $INET_IF -s $LAN_IP_RANGE -j SNAT --to-source $INET_IP
fi
/***** nat服务器搭建完毕!把/bin/nat.sh添加到rc.local中实现开机启动! *****/
/***** 接着搭建dhcp服务器让内网主机自动获取ip,修改dhcpd.conf,内容如下: *****/
/***** /etc/dhcpd.conf *****/
ddns-update-style interim;
ignore client-updates;
subnet 192.168.1.0 netmask 255.255.255.0 {
# --- default gateway
option routers 192.168.1.254;#(内网网关)
option subnet-mask 255.255.255.0;
# option nis-domain "domain.org";
# option domain-name "domain.org";
option domain-name-servers 211.84.160.8, 202.102.224.68;
#(域名服务器,根据具体网络环境设定)
option time-offset -18000; # Eastern Standard Time
# option ntp-servers 192.168.1.1;
# option netbios-name-servers 192.168.1.1;
# --- Selects point-to-point node (default is hybrid). Don't change this unless
# -- you understand Netbios very well
# option netbios-node-type 2;
range dynamic-bootp 192.168.1.100 192.168.1.200;#(预动态分配的内网IP范围)
default-lease-time 21600;
max-lease-time 43200;
# we want the nameserver to appear at a fixed address
# host ns {
# next-server marvin.redhat.com;
# hardware ethernet 12:34:56:78:AB:CD;
# fixed-address 207.175.42.254;
# }
}
重启DHCP服务器!看是否成功!若不成功,说明配置文件有误!
剩下的工作就是在内部主机上搭建WWW服务器,注:WWW服务器在这里是192.168.1.80这台主机!
注:本内容的编写者主要是2009级 嵌入式方向学生:王晓峰、闫俊霖、王延龙等。
一,搭建NAT服务器实现内网与外网相互访问;
二,搭建DHCP服务器便于对内网主机网络参数的管理;
三,在内网主机上搭建WWW服务器(这里是在"192.168.1.80"主机上);
以下是具体实现过程:
(eth1为外网接口,etho为内网接口) *****/
/***** 在/bin下新建nat.sh,内容如下: *****/
/***** nat.sh *****/
#!/bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward
#echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
#echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
#INET_IF="ppp0"
INET_IF="eth1"
LAN_IF="eth0"
INET_IP="218.198.18.56" #(根据具体网络环境设定)
WWW_IP="192.168.1.80" #(搭建www服务器的内网主机)
LAN_IP_RANGE="192.168.1.0/24"
IPT="/sbin/iptables"
TC="/sbin/tc"
MODPROBE="/sbin/modprobe"
$MODPROBE ip_tables
$MODPROBE iptable_nat
$MODPROBE ip_nat_ftp
$MODPROBE ip_nat_irc
$MODPROBE ipt_mark
$MODPROBE ip_conntrack
$MODPROBE ip_conntrack_ftp
$MODPROBE ip_conntrack_irc
$MODPROBE ipt_MASQUERADE
for TABLE in filter nat mangle ; do
$IPT -t $TABLE -F
$IPT -t $TABLE -X
$IPT -t $TABLE -Z
done
$IPT -P INPUT ACCEPT
$IPT -P OUTPUT ACCEPT
$IPT -P FORWARD ACCEPT
$IPT -t nat -P PREROUTING ACCEPT
$IPT -t nat -P OUTPUT ACCEPT
$IPT -t nat -P POSTROUTING ACCEPT
# 拒绝INTERNET客户访问
$IPT -A INPUT -i $INET_IF -m state --state RELATED,ESTABLISHED -j ACCEPT
#$IPT -A INPUT -i $INET_IF -p tcp -s 123.5.0.0/16 --dport 22 -j ACCEPT
#$IPT -A INPUT -i $INET_IF -p tcp --dport 80 -j ACCEPT
$IPT -A INPUT -i $LAN_IF -p udp --dport 67 -j ACCEPT
$IPT -A INPUT -i $INET_IF -m state --state NEW,INVALID -j DROP
for DNS in $(grep ^n /etc/resolv.conf|awk '{print $2}'); do
$IPT -A INPUT -p tcp -s $DNS --sport domain -j ACCEPT
$IPT -A INPUT -p udp -s $DNS --sport domain -j ACCEPT
done
# anti bad scaning
$IPT -A INPUT -i $INET_IF -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP
$IPT -A INPUT -i $INET_IF -p tcp --tcp-flags ALL ALL -j DROP
$IPT -A INPUT -i $INET_IF -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
$IPT -A INPUT -i $INET_IF -p tcp --tcp-flags ALL NONE -j DROP
$IPT -A INPUT -i $INET_IF -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
$IPT -A INPUT -i $INET_IF -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
$IPT -t nat -A PREROUTING -d $INET_IP -p tcp --dport 80 -j DNAT --to-destination $WWW_IP:80
#(以上这条规则很重要,实现外网通过80端口访问内网WWW服务器)
if [ $INET_IF = "ppp0" ] ; then
$IPT -t nat -A POSTROUTING -o $INET_IF -s $LAN_IP_RANGE -j MASQUERADE
else
$IPT -t nat -A POSTROUTING -o $INET_IF -s $LAN_IP_RANGE -j SNAT --to-source $INET_IP
fi
/***** nat服务器搭建完毕!把/bin/nat.sh添加到rc.local中实现开机启动! *****/
/***** 接着搭建dhcp服务器让内网主机自动获取ip,修改dhcpd.conf,内容如下: *****/
/***** /etc/dhcpd.conf *****/
ddns-update-style interim;
ignore client-updates;
subnet 192.168.1.0 netmask 255.255.255.0 {
# --- default gateway
option routers 192.168.1.254;#(内网网关)
option subnet-mask 255.255.255.0;
# option nis-domain "domain.org";
# option domain-name "domain.org";
option domain-name-servers 211.84.160.8, 202.102.224.68;
#(域名服务器,根据具体网络环境设定)
option time-offset -18000; # Eastern Standard Time
# option ntp-servers 192.168.1.1;
# option netbios-name-servers 192.168.1.1;
# --- Selects point-to-point node (default is hybrid). Don't change this unless
# -- you understand Netbios very well
# option netbios-node-type 2;
range dynamic-bootp 192.168.1.100 192.168.1.200;#(预动态分配的内网IP范围)
default-lease-time 21600;
max-lease-time 43200;
# we want the nameserver to appear at a fixed address
# host ns {
# next-server marvin.redhat.com;
# hardware ethernet 12:34:56:78:AB:CD;
# fixed-address 207.175.42.254;
# }
}
重启DHCP服务器!看是否成功!若不成功,说明配置文件有误!
剩下的工作就是在内部主机上搭建WWW服务器,注:WWW服务器在这里是192.168.1.80这台主机!
注:本内容的编写者主要是2009级 嵌入式方向学生:王晓峰、闫俊霖、王延龙等。
0
上一篇:GRUB(GRand Unified Boot loader)引导加载程序
下一篇:论文 毕业设计 相关 用语 评语
相关热门文章
- linux 常见服务端口
- xmanager 2.0 for linux配置
- 【ROOTFS搭建】busybox的httpd...
- openwrt中luci学习笔记
- 什么是shell
- linux dhcp peizhi roc
- 关于Unix文件的软链接
- 求教这个命令什么意思,我是新...
- sed -e "/grep/d" 是什么意思...
- 谁能够帮我解决LINUX 2.6 10...
给主人留下些什么吧!~~
评论热议
0 0
- NAT DHCP WWW rc.local
- NAT DHCP WWW rc.local
- NAT DHCP WWW rc.local
- rc.local nat
- rc.local
- rc.local
- rc.local
- rc.local
- rc.local
- rc.local
- DHCP+NAT路由实验
- DHCP+NAT+IP隧道
- Debian中的rc.local
- 说说rc.local
- ubuntu rc.local
- Ubuntu自定义rc.local
- 说说rc.local
- 说说rc.local
- mysql启动停止
- nodejs在线xlsx转json
- Erlang并发编程
- rhel/centos播放mp3文件
- GRUB(GRand Unified Boot loader)引导加载程序
- NAT DHCP WWW rc.local
- 论文 毕业设计 相关 用语 评语
- 基于EasyDarwin远程视频传输
- Random的setSeed方法
- linux下查看uuid
- IT公司中最流行的10种编程语言
- MySql绿色版配置及使用详解
- C会否像汇编一样退居幕后?
- CCV库安装
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
周飞
周驹
周驹在台湾结果
周鸿 波士堂
莎顶顶
撒顶顶
神级捡漏周鼎
呪
呪怎么读
呱噪
呱太
呲
呲呲
呲牙
呲哩呲哩
呲花
呲溜
呲水
大呲花
呲牙咧嘴
呲怎么读
大呲花什么意思
呲哩磁力搜索
呲哌酸片冶拉肚子吗
呲牙表情
呲牙笑表情包
呲牙图片
缸垫呲了什么症状
汽车缸垫呲了有什么现象
睚呲必报什么意思
美国十呲啦 亚洲入口
酮康挫
呲牙表情是什么意思
狗对主人呲牙
呲牙咧嘴的意思
呲花哥讲段子
呲花烟花图片
甜味儿alpha
内味儿
味儿
有内味儿