LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 819|回复: 5

问下单网卡ADSL共享设置方法

[复制链接]
发表于 2005-5-31 16:24:05 | 显示全部楼层 |阅读模式
ADSL接交换机uplink口... 网卡接交换机....

系统ubuntu 5.4

看了好多文章都是双网卡共享的... 不知道单网卡如何配置?
发表于 2005-5-31 16:28:52 | 显示全部楼层
如果你是ADSL拨号上网,把那些资料中的 eth1 或 eth0 换成 ppp0。
回复 支持 反对

使用道具 举报

发表于 2005-5-31 16:45:25 | 显示全部楼层
修改adsl-start启动脚本如下(MDV LE2005),加入了共享代码:
  1. #!/bin/sh
  2. # Generated automatically from adsl-start.in by configure.
  3. #***********************************************************************
  4. #
  5. # adsl-start
  6. #
  7. # Shell script to bring up an ADSL connection
  8. #
  9. # Copyright (C) 2000 Roaring Penguin Software Inc.
  10. #
  11. # $Id: adsl-start.in,v 1.8 2002/04/09 17:28:39 dfs Exp $
  12. #
  13. # This file may be distributed under the terms of the GNU General
  14. # Public License.
  15. #
  16. # LIC: GPL
  17. #
  18. # Usage: adsl-start [config_file]
  19. #        adsl-start interface user [config_file]
  20. # Second form overrides USER and ETH from config file.
  21. # If config_file is omitted, defaults to /etc/ppp/pppoe.conf
  22. #
  23. #***********************************************************************

  24. # From AUTOCONF
  25. prefix=/usr
  26. exec_prefix=/usr

  27. # Paths to programs
  28. CONNECT=/usr/sbin/adsl-connect
  29. ECHO=/bin/echo
  30. IFCONFIG=/sbin/ifconfig

  31. # Set to "C" locale so we can parse messages from commands
  32. LANG=C
  33. export LANG

  34. # Defaults
  35. CONFIG=/etc/ppp/pppoe.conf
  36. USER=""
  37. ETH=""
  38. ME=`basename $0`
  39. # Must be root
  40. if [ "`/bin/id -u`" != 0 ] ; then
  41.     $ECHO "$ME: You must be root to run this script" >& 2
  42.     exit 1
  43. fi

  44. # Debugging
  45. if [ "$DEBUG" = "1" ] ; then
  46.     $ECHO "*** Running in debug mode... please be patient..."
  47.     DEBUG=/tmp/pppoe-debug-$$
  48.     export DEBUG
  49.     mkdir $DEBUG
  50.     if [ "$?" != 0 ] ; then
  51.         $ECHO "Could not create directory $DEBUG... exiting"
  52.         exit 1
  53.     fi
  54.     DEBUG=$DEBUG/pppoe-debug.txt

  55.     # Initial debug output
  56.     $ECHO "---------------------------------------------" > $DEBUG
  57.     $ECHO "* The following section contains information about your system" >> $DEBUG
  58.     date >> $DEBUG
  59.     $ECHO "Output of uname -a" >> $DEBUG
  60.     uname -a >> $DEBUG
  61.     $ECHO "---------------------------------------------" >> $DEBUG
  62.     $ECHO "* The following section contains information about your network" >> $DEBUG
  63.     $ECHO "* interfaces.  The one you chose for PPPoE should contain the words:" >> $DEBUG
  64.     $ECHO "* 'UP' and 'RUNNING'.  If it does not, you probably have an Ethernet" >> $DEBUG
  65.     $ECHO "* driver problem." >> $DEBUG
  66.     $ECHO "Output of ifconfig -a" >> $DEBUG
  67.     $IFCONFIG -a >> $DEBUG
  68.     $ECHO "---------------------------------------------" >> $DEBUG
  69.     if [ "`uname -s`" = "Linux" ] ; then
  70.         $ECHO "* The following section contains information about kernel modules" >> $DEBUG
  71.         $ECHO "* If the module for your Ethernet card is 'tulip', you might" >> $DEBUG
  72.         $ECHO "* want to look for an updated version at http://www.scyld.com" >> $DEBUG
  73.         $ECHO "Output of lsmod" >> $DEBUG
  74.         lsmod >> $DEBUG
  75.         $ECHO "---------------------------------------------" >> $DEBUG
  76.     fi
  77.     $ECHO "* The following section lists your routing table." >> $DEBUG
  78.     $ECHO "* If you have an entry which starts with '0.0.0.0', you probably" >> $DEBUG
  79.     $ECHO "* have defined a default route and gateway, and pppd will" >> $DEBUG
  80.     $ECHO "* not create a default route using your ISP.  Try getting" >> $DEBUG
  81.     $ECHO "* rid of this route." >> $DEBUG
  82.     $ECHO "Output of netstat -n -r" >> $DEBUG
  83.     netstat -n -r >> $DEBUG
  84.     $ECHO "---------------------------------------------" >> $DEBUG
  85.     $ECHO "Contents of /etc/resolv.conf" >> $DEBUG
  86.     $ECHO "* The following section lists DNS setup." >> $DEBUG
  87.     $ECHO "* If you can browse by IP address, but not name, suspect" >> $DEBUG
  88.     $ECHO "* a DNS problem." >> $DEBUG
  89.     cat /etc/resolv.conf >> $DEBUG
  90.     $ECHO "---------------------------------------------" >> $DEBUG
  91.     $ECHO "* The following section lists /etc/ppp/options." >> $DEBUG
  92.     $ECHO "* You should have NOTHING in that file." >> $DEBUG
  93.     $ECHO "Contents of /etc/ppp/options" >> $DEBUG
  94.     cat /etc/ppp/options >> $DEBUG 2>/dev/null
  95.     $ECHO "---------------------------------------------" >> $DEBUG
  96. else
  97.     DEBUG=""
  98. fi

  99. # Sort out command-line arguments
  100. case "$#" in
  101.     1)
  102.         CONFIG="$1"
  103.         ;;
  104.     3)
  105.         CONFIG="$3"
  106.         ;;
  107. esac

  108. if [ ! -f "$CONFIG" -o ! -r "$CONFIG" ] ; then
  109.     $ECHO "$ME: Cannot read configuration file '$CONFIG'" >& 2
  110.     exit 1
  111. fi

  112. . $CONFIG

  113. # Check for command-line overriding of ETH and USER
  114. case "$#" in
  115.     2|3)
  116.         ETH="$1"
  117.         USER="$2"
  118.         ;;
  119. esac

  120. # Check for pidfile
  121. if [ -r "$PIDFILE" ] ; then
  122.     PID=`cat "$PIDFILE"`
  123.     # Check if still running
  124.     kill -0 $PID > /dev/null 2>&1
  125.     if [ $? = 0 ] ; then
  126.         $ECHO "$ME: There already seems to be an ADSL connection up (PID $PID)" >& 2
  127.         exit 1
  128.     fi
  129.     # Delete bogus PIDFILE
  130.     rm -f "$PIDFILE" "$PIDFILE.pppd" "$PIDFILE.pppoe" "$PIDFILE.start"
  131. fi

  132. echo $$ > $PIDFILE.start

  133. # Start the connection in the background unless we're debugging
  134. if [ "$DEBUG" != "" ] ; then
  135.     $CONNECT "$@"
  136.     exit 0
  137. fi

  138. $CONNECT "$@" > /dev/null 2>&1 &
  139. CONNECT_PID=$!

  140. if [ "$CONNECT_TIMEOUT" = "" -o "$CONNECT_TIMEOUT" = 0 ] ; then
  141.     exit 0
  142. fi

  143. # Don't monitor connection if dial-on-demand
  144. if [ "$DEMAND" != "" -a "$DEMAND" != "no" ] ; then
  145.     exit 0
  146. fi

  147. # Monitor connection
  148. TIME=0
  149. while [ true ] ; do
  150.     /usr/sbin/adsl-status $CONFIG > /dev/null 2>&1

  151.     # Looks like the interface came up
  152.     if [ $? = 0 ] ; then
  153.         # Print newline if standard input is a TTY
  154.         tty -s && $ECHO " Connected!"
  155.         ################ added for pppoe sharing ##################
  156.         INET_FACE="$(ls /proc/sys/net/ipv4/conf | grep ppp)"
  157.         INET_ADDR="$(ifconfig ${INET_FACE} | awk -F: '{print $2}' | awk '{print $1}' | grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}')"
  158.         #Reset firewall
  159.         iptables -P INPUT ACCEPT
  160.         iptables -P FORWARD ACCEPT
  161.         iptables -P OUTPUT ACCEPT
  162.         iptables -t nat -P PREROUTING ACCEPT
  163.         iptables -t nat -P POSTROUTING ACCEPT
  164.         iptables -t nat -P OUTPUT ACCEPT
  165.         iptables -t mangle -P PREROUTING ACCEPT
  166.         iptables -t mangle -P OUTPUT ACCEPT
  167.         iptables -F
  168.         iptables -t nat -F
  169.         iptables -t mangle -F
  170.         iptables -X
  171.         iptables -t nat -X
  172.         iptables -t mangle -X

  173.         #Start firewall
  174.         iptables -P INPUT DROP
  175.         iptables -A INPUT -i ! $INET_FACE -j ACCEPT
  176.         iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  177.         iptables -A INPUT -p tcp -i $INET_FACE -j REJECT --reject-with tcp-reset
  178.         iptables -A INPUT -p udp -i $INET_FACE -j REJECT --reject-with icmp-port-unreachable

  179.         iptables -P FORWARD DROP
  180.         iptables -A FORWARD -i ! $INET_FACE -j ACCEPT
  181.         iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

  182.         #Enable IP forwarding
  183.         echo 1 > /proc/sys/net/ipv4/ip_forward

  184.         #Use snat
  185.         iptables -t nat -A POSTROUTING -o $INET_FACE -j SNAT --to-source $INET_ADDR
  186.         #################### end of pppoe sharing code ###########
  187.         exit 0
  188.     fi

  189.     if test -n "$FORCEPING" ; then
  190.         $ECHO -n "$FORCEPING"
  191.     else
  192.         tty -s && $ECHO -n "$PING"
  193.     fi
  194.     sleep $CONNECT_POLL
  195.     TIME=`expr $TIME + $CONNECT_POLL`
  196.     if [ $TIME -gt $CONNECT_TIMEOUT ] ; then
  197.         break
  198.     fi
  199. done

  200. $ECHO "TIMED OUT" >& 2
  201. # Timed out!  Kill the adsl-connect process and quit
  202. kill $CONNECT_PID > /dev/null 2>&1

  203. # Clean up PIDFILE(s)
  204. rm -f "$PIDFILE" "$PIDFILE.pppd" "$PIDFILE.pppoe" "$PIDFILE.start"

  205. exit 1
复制代码
回复 支持 反对

使用道具 举报

发表于 2005-5-31 21:38:55 | 显示全部楼层
服务器端2条指令搞定:
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o ppp+ -j MASQUERADE

客户端就不用说了吧。
服务器端拨号成功后局域网中其他机器(192.168.1.0/24)就可以上网了。
回复 支持 反对

使用道具 举报

发表于 2005-6-1 02:39:11 | 显示全部楼层
如果猫带路由功能的话,就用不着双网卡了。。。配置起来也挺容易的。。
回复 支持 反对

使用道具 举报

发表于 2005-6-2 17:07:07 | 显示全部楼层
猫带路由性能很局限,往往会造成带宽无法达到原有的速度。不推荐使用。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表