[问题]校园网、局域网共享上网问题,急盼解决!

包含网卡/无线网的网络问题和ADSL/校园网/宽带拨号支持及代理/共享等网络使用问题
回复
天下一路人
帖子: 9
注册时间: 2007-05-13 18:09

[问题]校园网、局域网共享上网问题,急盼解决!

#1

帖子 天下一路人 » 2008-04-21 11:16

要求:UBUNTU作服务器,共享网络连接供局域网内客户机访问互联网。
网络环境:
1、主机:
操作系统:UBUNTU
网卡:双网卡
网卡1:固定IP(学校分配),能上互联网。
网卡2:固定IP,192.168.1.2通过交换机连接本办公室组建的局域网。
2、客户机:
操作系统:windows XP
网卡:单网卡,固定IP,192.168.1.3-192.168.1.100

如果主机的操作系统使用Windows 2003,操作及其简单:将第一张网卡共享,然后在客户机IP设置中,将网关和DNS设为主机第二张网卡的IP就OK了,为什么UBUNTU设置这么困难?
在网上搜了很久,只发现两种方法
1、通过安装firestarter来实现,但是在ubuntu 8.04中使用firestarter不疯人也会崩溃,超级麻烦。
2、用iptables开启nat功能:找了N久,也没有见到一篇有用的教程。

正在绝望中......
dbzhang800
帖子: 3182
注册时间: 2006-03-10 15:10
来自: xi'an China
联系:

#2

帖子 dbzhang800 » 2008-04-21 11:40

哪有像你说的这么困难 :D :D

(来源:http://linux.vbird.org/download/index.p ... &fileid=43)

代码: 全选

#!/bin/bash
#
# ========================================================
# 程序说明:
# 欢迎使用 iptables.rule 这个 script 来建立您的防火墙!
# 这支 script 还需要您的额外设定方可适合您的主机环境!
# 基本规则定义为 拒绝所有,开放特定 的模式!
#
# 强烈建议:
# 不了解 Linux 防火墙机制 iptables 的朋友使用这支 script
# 可能会不太了解每个指令列的意义,果真如此的话,
# 欢迎参考底下几个网页:
# http://www.study-area.org/linux/servers/linux_nat.htm
# http://linux.vbird.org/linux_server/0240network-secure-1.php
# http://linux.vbird.org/linux_server/0250simple_firewall.php
#
# 使用说明:
# 确定这个程序仅有 Linux 的断行字元:
# dos2unix iptables.rule
# 请先将这个 scripts 的权限更改为可执行:
#       chmod 755 iptables.rule
# 在将这个程序放置在 /usr/local/virus/iptables 目录下:
#       mkdir -p /usr/local/virus/iptables
#       mv /完整的路径/iptables.rule /usr/local/virus/iptables
# 执行测试:
#       /usr/local/virus/iptables/iptables.rule
#       iptables -L -n   (这个动作在检查防火墙规则)
# 将底下这一行加入 /etc/rc.d/rc.local 当中
#       /usr/local/virus/iptables/iptables.rule
# 取消防火墙:
#       iptables -F
#       iptables -X
#       iptables -t nat -F
#       iptables -t nat -X
#
# ========================================================
# 版权宣告:
# 这支程序为 GPL 授权,任何人皆可使用,
# 然,若使用本 scripts 发生问题时,本人不负任何责任
# VBird 
# ========================================================
#
# 历史纪录:
# 2002/08/20    VBird   首次释出
# 2003/04/26    VBird   加入砍站软件的相关执行档案!
# 2003/08/25    VBird   修改 INPUT 的 Policy 成为 DROP
# 2006/09/13 VBird 重新修订,加入一些核心参数 /proc/sys/net/ipv4/*
# 2006/09/15 VBird   加入关於 NAT 主机后端服务器的转址功能。
# 2006/09/30 VBird 加入每个设定项目的英文说明!!
# 2006/11/08 VBird 参考朋友们发现的 PPPoE 导致 MTU 的问题,增加一条规则!在 NAT 的部分。
#
###########################################################################################

# 请先输入您的相关参数,不要输入错误了!
# English: Please input your networks parameters ( including your LAN NIC )
EXTIF="eth0"    # 这个是可以连上 Public IP 的网络介面,也可能是 ppp0
     # This is your NIC, connect to internet. Such as ppp0...
#  INIF="eth0"    # 內部 LAN 的连接介面;若无 LAN ,填写成 INIF="" ;不能用 eth0:2等
     # This is your LAN NIC.  If you don't have a LAN, input INIF="" please.
INNET="192.168.1.0/24"  # 若有两个以上的网域,可以用 INNET="192.168.1.0/24 192.168.100.0/24"
     # 若无內部网域介面,请填写成 INNET=""
     # This is your LAN's Network.  If you have to private network,
     # input as INNET="192.168.1.0/24 192.168.100.0/24".
export EXTIF INIF INNET

# 个人化设定啊!请自行填写您自己想要预先启动的一些基础资料。
# These settings is about yourself's paramters.
allowname=''   # 允许登入本机的 hostname ,必须是 Internet 找的到的 hostname。
allowip=""
if [ "$allowname" != "" ]; then
 for siteiptmp in `echo $allowname`
 do
       siteip=`/usr/bin/host $siteiptmp 168.95.1.1    | grep address|tail -n 1 | awk '{print $4}'`
       testip=`echo $siteip | grep [^0-9.]`
       if [ "$testip" == "" ]; then
            allowip="$allowip  $siteip"
       fi
 done
fi
export allowip

# 第一部份,针对本机的防火墙设定!#########################################################
# First, your server's firewall settings.
# 1. 先设定好核心的网络功能:
# 1. the kernel's firewall settings.
# 开启 TCP Flooding 的 DoS 攻擊抵挡机制,但这个设定不适合 loading 已经很高的主机!!!
# TCP Flooding's setting.  this setting is no good for high loading servers
echo "1" > /proc/sys/net/ipv4/tcp_syncookies
# 取消 ping 广播的回应;
# unset reply of ping.
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
# 开启逆向路径过滤,以符合 IP 封包与网络介面的设定;
#
for i in /proc/sys/net/ipv4/conf/*/rp_filter; do
 echo "1" > $i
done
# 开启记录有问题的封包
# record some problems packets.
for i in /proc/sys/net/ipv4/conf/*/log_martians; do
 echo "1" > $i
done
# 取消来源路由,这个设定值是可以取消的;
for i in /proc/sys/net/ipv4/conf/*/accept_source_route; do
 echo "0" > $i
done
# 取消重新宣告路径的功能。
for i in /proc/sys/net/ipv4/conf/*/accept_redirects; do
 echo "0" > $i
done
# 取消传送重新宣告路径的功能。
for i in /proc/sys/net/ipv4/conf/*/send_redirects; do
 echo "0" > $i
done

# 2. 清除规则、设定预设政策及开放 lo 与相关的设定值
# 2. clear rule, set the policy rule and allow lo connect.
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin; export PATH
iptables -F
iptables -X
iptables -Z
iptables -P INPUT   DROP
iptables -P OUTPUT  ACCEPT
iptables -P FORWARD ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state RELATED -j ACCEPT

# 3. 启动额外的防火墙 script 模组
# 3. other shell scripts, written by VBird.
# 预设抵挡的主机
if [ -f /usr/local/virus/iptables/iptables.deny ]; then
 sh /usr/local/virus/iptables/iptables.deny
fi
# 预设开放的主机
if [ -f /usr/local/virus/iptables/iptables.allow ]; then
 sh /usr/local/virus/iptables/iptables.allow
fi
# 透过 WWW 砍站软件分析的抵挡机制
if [ -f /usr/local/virus/httpd-err/iptables.http ]; then
     sh /usr/local/virus/httpd-err/iptables.http
fi
iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT

# 4. 允许某些类型的 ICMP 封包进入
# 4. allow some types of ICMP
AICMP="0 3 3/4 4 11 12 14 16 18"
for tyicmp in $AICMP
do
 iptables -A INPUT -i $EXTIF -p icmp --icmp-type $tyicmp -j ACCEPT
done

# 5. 允许某些服务的进入
# iptables -A INPUT -p TCP -i $EXTIF --dport  22  -j ACCEPT # SSH
# iptables -A INPUT -p TCP -i $EXTIF --dport  25  -j ACCEPT # SMTP
# iptables -A INPUT -p UDP -i $EXTIF --dport  53  -j ACCEPT # DNS
# iptables -A INPUT -p TCP -i $EXTIF --dport  53  -j ACCEPT # DNS
# iptables -A INPUT -p TCP -i $EXTIF --dport  80  -j ACCEPT # WWW
# iptables -A INPUT -p TCP -i $EXTIF --dport 110  -j ACCEPT # POP3
# iptables -A INPUT -p TCP -i $EXTIF --dport 443  -j ACCEPT # HTTPS


# 第二部份,针对后端主机的防火墙设定!#########################################################
# Second, the NAT settings.
# 1. 先载入一些有用的模组
# 1. loading some good modules of iptables.
modules="ip_tables iptable_nat ip_nat_ftp ip_nat_irc ip_conntrack ip_conntrack_ftp ip_conntrack_irc"
for mod in $modules
do
 testmod=`lsmod | grep "^${mod} " | awk '{print $1}'`
 if [ "$testmod" == "" ]; then
  modprobe $mod
 fi
done

# 2. 清除 NAT table 的规则吧!
# 2. clean NAT table's rule
iptables -F -t nat
iptables -X -t nat
iptables -Z -t nat
iptables -t nat -P PREROUTING  ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t nat -P OUTPUT      ACCEPT

# 3. 开放成为路由器,且为 IP 分享器!
# 3. NAT server's settings
if [ "$INIF" != "" ]; then
 iptables -A INPUT -i $INIF -j ACCEPT
 echo "1" > /proc/sys/net/ipv4/ip_forward
 if [ "$INNET" != "" ]; then
  for innet in $INNET
  do
   iptables -t nat -A POSTROUTING -s $innet -o $EXTIF -j MASQUERADE
  done
 fi
fi
# 如果你的 MSN 一直无法连线,或者是某些网站 OK 某些网站不 OK,可能是 MTU 的问题,
# 那你可以将底下这一行给他取消注解来启动 MTU 限制范围
# iptables -A FORWARD -p tcp -m tcp --tcp-flags SYN,RST SYN -m tcpmss --mss 1400:1536 -j TCPMSS --clamp-mss-to-pmtu

# 4. NAT 主机后端的 LAN 內对外之服务器设定
# iptables -t nat -A PREROUTING -p tcp -i $EXTIF --dport 80 -j DNAT --to 192.168.1.210:80 # WWW
marijuana
帖子: 16
注册时间: 2008-03-08 11:23

#3

帖子 marijuana » 2008-04-28 22:06

我也遇到了跟搂主一样的问题呀。
同样是google了下教程。7.10下先装了个firestarter,然后在首选项里设置网络参数,居然提示eth1 没准备好。
查看了下ifconfig内容如下:
eth0 链路封装:以太网 硬件地址 00:E0:18:E2:8C:DB
inet 地址:192.168.11.254 广播:192.168.11.255 掩码:255.255.255.0
inet6 地址: fe80::2e0:18ff:fee2:8cdb/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 跃点数:1
接收数据包:620 错误:0 丢弃:0 过载:0 帧数:0
发送数据包:327 错误:0 丢弃:0 过载:0 载波:0
碰撞:0 发送队列长度:1000
接收字节:50840 (49.6 KB) 发送字节:26380 (25.7 KB)
中断:20

eth1 链路封装:以太网 硬件地址 52:54:AB:30:68:04
inet6 地址: fe80::5054:abff:fe30:6804/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 跃点数:1
接收数据包:9417 错误:0 丢弃:0 过载:0 帧数:0
发送数据包:3234 错误:0 丢弃:0 过载:0 载波:0
碰撞:302 发送队列长度:1000
接收字节:3724824 (3.5 MB) 发送字节:442757 (432.3 KB)
中断:18 基本地址:0xb800

eth1:avah 链路封装:以太网 硬件地址 52:54:AB:30:68:04
inet 地址:169.254.3.239 广播:169.254.255.255 掩码:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 跃点数:1
中断:18 基本地址:0xb800

lo 链路封装:本地环回
inet 地址:127.0.0.1 掩码:255.0.0.0
inet6 地址: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 跃点数:1
接收数据包:24 错误:0 丢弃:0 过载:0 帧数:0
发送数据包:24 错误:0 丢弃:0 过载:0 载波:0
碰撞:0 发送队列长度:0
接收字节:2046 (1.9 KB) 发送字节:2046 (1.9 KB)

ppp0 链路封装:点对点协议
inet 地址:10.10.11.77 点对点:10.0.0.1 掩码:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1492 跃点数:1
接收数据包:672 错误:0 丢弃:0 过载:0 帧数:0
发送数据包:765 错误:0 丢弃:0 过载:0 载波:0
碰撞:0 发送队列长度:3
接收字节:706815 (690.2 KB) 发送字节:78195 (76.3 KB)
试过了,只能eth1用漫游或者 DHCP否则主机无法访问广域网,但firestarter就是提示这个设备无效@_@。

然后参照论坛里的这个帖子开启NAT viewtopic.php?p=503987&sid=ace57595ce6b ... 46906be5b4
还寻思,ADSL和校园里都是pppoe连接的,道理应该一样吧,基本上都按帖子里的做了,只改了下最后一句
ptables -t nat -A POSTROUTING -o ppp0 -s 192.168.11.0/24 -j MASQUERADE (因为内网分配时用了192.168.11.*)
结果还是不行……

按楼上的到鸟哥那里看了,下载不了那个 rule文件,web打开是乱码(ubuntu firefox 2.0.14)....
复制楼上的脚本自己保存了个iptables.rule, chmod 755 执行后还是不行

对了,还有,做了上面的工作后我用gedit查看 /proc/sys/net/ipv4/ip_forward 的内容怎么是空的?? 应该有什么内容在里面?
回复