Linux 双网卡共享上网配置

以下文章主要跟据网上资料载录收集在一起:

一、ADSL 方案的配置

   主要配置方法为通过,adsl-setup 命令进行配置。

1.adsl-setup

  ....

2.根据提示,配置好后执行以下命令即可拨号

#adsl-start

#adsl-stop --断开连接

#adsl-status 查看连接状态

 

在rc.local 中配置:

echo "1" >/proc/sys/net/ipv4/ip_forward   进行包转发

或者编辑文件:

   修改/etc/sysctl.conf,在文件中加上下面一行: net.ipv4.ip_forward= 1,这里就是开启NAT。1表示转发,如果设置为0的话就是不转发。

   在ppp0 上启用包转发功能:

iptables -t nat -A POSTROUTING -O PPP0 -j MASQUERADE

 

3.then reboot system.

 

二、光纤,或固定IP方式上网配置

   eth0: 固定IP 211.156.179.114 接外网

   eth1:192.168.50.1  做网关

   在rc.local 中加入如下命令:

iptables -F    清楚之前的规则
iptables -P INPUT ACCEPT   允许接收数据包
iptables -P FORWARD ACCEPT  允许发送包
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j MASQUERADE

 

在eth0 上启用nat 功能

   修改/etc/sysctl.conf,在文件中加上下面一行: net.ipv4.ip_forward= 1,这里就是开启NAT。1表示转发,如果设置为0的话就是不转发。

 

 

 pppoe连接建立后,系统自动调用/etc/ppp/ip-up脚本。
其参数如下面文件所示,第4个参数是系统获得的动态ip。
#!/bin/bash
#
# Script which handles the routing issues as necessary for pppd
# Only the link to Newman requires this handling.
#
# When the ppp link comes up, this script is called with the following
# parameters
# $1 the interface name used by pppd (e.g. ppp3)
# $2 the tty device name
# $3 the tty device speed
# $4 the local IP address for the interface
# $5 the remote IP address
# $6 the parameter specified by the 'ipparam' option to pppd
#
PATH=/sbin:/usr/sbin:/bin:/usr/bin
export PATH
route add default gw $4
#下面这一行是使用3322.org的动态域名,如没有使用,可以不加。
/usr/local/bin/ez-ipupdate -c /usr/local/ezip/qdns.conf


把以上内容存为/etc/ppp/ip-up.local
并chmod 755 /etc/ppp/ip-up.local,使之有执行权限。
因为ip-up会自动找ip-up.local执行,所以不用修改ip-up文件。

最后执行:
service network restart
ip addr
(多看几次ip,如果ppp0获取了ip地址,则用route查看网关是否已经自动添加)
route
祝您成功!

 

你可能感兴趣的:(linux,service,脚本,input,NetWork,interface)