将要添加的零散IP保存到文件,判断IP网段添加IP时设定相应的掩码。
#!/bin/bash
for ip in `cat ip.txt`
do
if [[ $ip =~ ^184.164.141 ]]
then
ip add add $ip/26 dev eth0
else
ip add add $ip/27 dev eth0
fi
done
发布时间:June 16, 2013 // 分类:Shell // No Comments
将要添加的零散IP保存到文件,判断IP网段添加IP时设定相应的掩码。
#!/bin/bash
for ip in `cat ip.txt`
do
if [[ $ip =~ ^184.164.141 ]]
then
ip add add $ip/26 dev eth0
else
ip add add $ip/27 dev eth0
fi
done
发布时间:June 14, 2013 // 分类:Linux基础 // No Comments
安装bridge工具:
yum/apt-get install bridge-utils
非远程连接使用brctl配置网桥:
brctl addbr br0
brctl addif br0 eth1
brctl addif br0 eth2
#删除网桥
ifconfig bridge down
brctl delbr bridge
本次配置使用修改网络配置文件方式,远程连接时使用brctl命令添加可能会导致服务器网络中断。
Centos下配置网桥:
#桥配置
DEVICE=br0
TYPE=Bridge
onboot=YES
BOOTPROTO=static
IPADDR=192.168.1.1
NETMASK=255.255.255.0
GATEWAY=192.168.1.255
#eth0
DEVICE=eth0
BRIDGE=br0
TYPE=Ethernet
onboot=YES
#eth1
DEVICE=eth1
BRIDGE=br1
TYPE=Ethernet
onboot=YES
Debian配置就简单多了:
auto eth0
iface eth0 inet manual
auto eth1
iface eth1 inet manual
auto br0
iface br0 inet static
bridge_ports eth0 eth1
address 192.168.1.1
broadcast 192.168.1.255
netmask 255.255.255.0
gateway 192.168.1.1
发布时间:June 13, 2013 // 分类:Iptables // No Comments
Iptables实现NAT是最基本的功能,大部分家用路由都是基于其SNAT方式上网,使用Iptables实现外网DNAT也很简单,不过经常会出现不能正常NAT的现象。
以下命令将客户端访问1.1.1.1的HTTP数据DNAT到2.2.2.2,很多人往往只做这一步,然后测试不能正常连接。
iptables -t nat -A PREROUTING -p tcp -d 1.1.1.1 --dport 80 -j DNAT --to 2.2.2.2:80
想像一下此时客户端访问1.1.1.1的数据流程:
客户端访问1.1.1.1
1.1.1.1根据Iptables DNA将数据包发往2.2.2.2,此时源IP为客户端IP
2.2.2.2处理后根据源IP直接向客户端返回数据,要知道此时客户端是直接和1.1.1.1连接的
然后呢,客户端不知所云,不能正常连接
最后还要添加一条SNAT规则,将发到2.2.2.2的数据包SNAT,1.1.1.1充当代理服务器的角色。
iptables -t nat -A POSTROUTING -d 2.2.2.2 -j SNAT --to-source 1.1.1.1
别忘记开启内核转发功能:
echo 1 > /proc/sys/net/ipv4/ip_forward
发布时间:June 12, 2013 // 分类:ROS // No Comments
和HE服务器建立IPV6 Tunnel连接:
/interface 6to4 add name=he-ipv6 remote-address=216.218.221.6 local-address=111.111.11.1 disabled=no
ROS添加HE分配的IPV6地址:
/ipv6 address add address=2001:470:18:5da::2/64 advertise=yes disabled=no eui-64=no interface=he-ipv6
ROS添加默认IPV6路由:
/ipv6 route add disabled=no dst-address=::/0 gateway=he-ipv6
测试IPV6:
ping 2404:6800:4008:c01::65
2404:6800:4008:c01::65 56 58 396ms echo reply
发布时间:June 11, 2013 // 分类:Linux服务 // No Comments
安装tunctl用于新建TAP/TUN设备,TAP为以太网设备,TUN为网络层设备。
yum install tunctl
#debian下为uml-utilities
Client配置:
tunctl -t tap1
ifconfig tap4 192.168.1.1 netmask 255.255.255.0 up
Server配置:
tunctl -t tap2
ifconfig tap2 192.168.1.2 netmask 255.255.255.0 up
echo "PermitTunnel yes" >> /etc/ssh/sshd_config
Client发起SSH Tunnel连接:
ssh -N -f -o Tunnel=ethernet -w 1:2 remote-host
#-w local tap id:remote tap id