萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 作業系統 >  >> Linux 教學

Linux 路由与 QoS 限速配置实战笔记:基于 Ubuntu Server 8.04

利用闲置老机器搭建路由器,记录实战过程与踩坑经验。网上教程错误较多,整理如下供参考。

一、安装 Ubuntu Server 8.04 与双网卡设置

eth0 为外网网卡,eth1 为内网网卡。编辑 /etc/network/interfaces:

auto eth0
iface eth0 inet static
address 外网IP
netmask 子网掩码
gateway 网关

auto eth1
iface eth1 inet static
address 内网IP
netmask 子网掩码

重启网络服务:sudo /etc/init.d/networking restart

二、设置 DNS 服务器

编辑 /etc/resolv.conf(Ubuntu 默认可能不存在,需自建):

nameserver 主DNS
nameserver 备用DNS

三、启用 IP 转发功能

检查内核是否开启转发:

sudo cat /proc/sys/net/ipv4/ip_forward

返回 0 则未启用,执行:

sudo echo 1 > /proc/sys/net/ipv4/ip_forward

四、设置 NAT 共享上网

固定公网 IP 方式:

sudo iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT --to XXX.XXX.XXX.XXX

XXX 为外网网卡 IP。防火墙规则暂未配置。

五、解决 ISP MAC 地址绑定问题

配置完成仍无法上网,发现 ISP 绑定 MAC。在网卡配置文件 eth0 段添加:

pre-up ifconfig eth0 hw ether 88:88:88:88:88:88

完整 eth0 配置:

auto eth0
iface eth0 inet static
pre-up ifconfig eth0 hw ether 88:88:88:88:88:88
address 外网IP
netmask 子网掩码
gateway 网关

重启网络服务生效。注:本文仅完成基本路由与 NAT,QoS 限速后续补充。

copyright © 萬盛學電腦網 all rights reserved