linux常见的网络操作命令
1 linux在某个网卡上面添加一条明细路由命令如下
命令的意思是在这台服务器上面添加一条网段为192.168.1.0/24,网关为192.168.2.1,通过eth0这个网卡口出去
ip router add 192.168.1.0/24 via 192.168.2.1 dev eth0
2 在linux某个网卡删除某条明细路由命令如下所示
ip router del 192.168.1.0/24 dev eth0
3 iptables相关命令
debian系统的iptables相关模版
#!/bin/bash # modprobe modules="ip_tables iptable_nat ip_nat_ftp ip_conntrack ip_conntrack_ftp" for mod in $modules do testmod=`lsmod | grep "^${mod} " | awk '{print $1}'` if [ "$testmod" == "" ]; then modprobe $mod fi done # sysctl #sysctl -w net.ipv4.tcp_syncookies=1 &> /dev/null #echo "1"> /proc/sys/net/ipv4/conf/eth0/rp_filter #echo "43200"> /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_timeout_established # nat iptables -t nat -F iptables -t nat -X iptables -t nat -Z iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -j MASQUERADE iptables -t nat -A PREROUTING -s 192.168.0.0/24 -p tcp --dport 53 -j DNAT --to 192.168.198.15 iptables -t nat -A PREROUTING -s 192.168.0.0/24 -p udp --dport 53 -j DNAT --to 192.168.198.15 ##filter重置 iptables -F iptables -X iptables -Z #################白名单############ iptables -P OUTPUT ACCEPT iptables -P FORWARD ACCEPT iptables -A INPUT -i lo -j ACCEPT iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT iptables -A INPUT -s 123.45.78.9/27 -j ACCEPT ##公网出口IP ##SSH iptables -A INPUT -p tcp --dport 23 -j ACCEPT iptables -A INPUT -p udp --dport 171 -j ACCEPT ###############黑名单############## iptables -P INPUT DROP #####开机启动项 iptables-save > /etc/iptables.up.rules echo '#!/bin/bash' > /etc/network/if-pre-up.d/iptables echo "/sbin/iptables-restore < /etc/iptables.up.rules" >>/etc/network/if-pre-up.d/iptables chmod +x /etc/network/if-pre-up.d/iptables