友链
导航
These are the good times in your life,
so put on a smile and it'll be alright
友链
导航
# 查看 arp 表 $ arp # 添加静态 arp 记录 # arp -s $IP $MAC $ arp -s 111.111.111.111 02:00:00:00:00:00 # 删除 arp 记录 # arp -d $IP $ arp -d 111.111.111.111 # arp 表在 ifdown 后会清空, 如需保留, # 可将静态 arp 记录按 $MAC $IP 格式写在 # /etc/ethers(建议的文件) 中 $ cat /etc/ethers 02:00:00:00:00:00 192.168.0.99 # 但此文件不会自动加载, 需 arp -f $FILE # 加载 $ cat /etc/network/interfaces iface eth0 inet dhcp up arp -f /etc/ethers
iputils-arping
包中的 arping 有 -U update neighbours' ARP caches 的功能, 可实现抢 IP. 如下:
$ sudo aptitude install iputils-arping $ arping -Uq -s192.168.5.5 -Ieth0 192.168.5.1 & # -U: Unsolicited ARP mode to update neighbours' ARP caches. No replies are expected. # -q: Quiet output. Nothing is displayed. # -s: source, IP source address to use in ARP packets. # -I: interface, Name of network device where to send ARP REQUEST packets. This option is required. # # 即更新 192.168.5.1 的 arp 表, 告诉它 192.168.5.5 对应的 mac 是本机的 eth0 # 命令可能有 ''Unicast reply from 192.168.5.1'' 的回应, 也可能没回应, 但应该都能产生效果(可由第三方 arp 192.168.5.5 看出)
一个技巧: 各桥接无线路由器的 SSID 可以设置成相同的,这样就能在这几个路由器覆盖范围内漫游
tcptunnel 是一个很方便的端口转发的工具, 暂无 apt 包, 需自行编译安装(依赖 make, gcc).
$ tcptunnel --help Usage: tcptunnel [options] Options: --version --help this help --local-port=PORT port to redirect --remote-port=PORT target port --remote-host=HOST target host --bind-address=IP bind IP address --stay-alive --log-to-stdout
把一台主机加入网络的基本步骤是:
以下是 Debian/Ubuntu 中的配置方法.
使用ifconfig
命令, 或是编辑/etc/network/interfaces
可配置网络接口, ifup/ifdown
可读取此文件, 通过调用下层命令如ifconfig
启动或停止接口.
# ifconfig命令的格式是: ifconfig interface address options ... $ ifconfig eth0 192.168.1.13 netmask 255.255.255.0 up
对于静态IP以太网接口, interfaces一般可做如下配置. 其中broadcast和gateway不是必须的. 两者中gateway(默认网关)更必须一点.
auto eth0 iface eth0 inet static address 192.168.0.42 network 192.168.0.0 netmask 255.255.255.0 broadcast 192.168.0.255 gateway 192.168.0.1 dns-nameservers 12.34.56.78 12.34.56.79
单网卡多 IP:
# The primary network interface auto eth0 iface eth0 inet static address 111.111.111.111 netmask 255.255.255.0 gateway 111.111.111.1 metric 0 # 虚拟网卡 auto eth0:0 iface eth0:0 inet static address 222.222.222.222 netmask 255.255.255.0 gateway 222.222.222.1 metric 1
下面这份配置利用{pre|_|post}{up|down}执行命令设置了更多路由信息:
auto eth0 iface eth0 inet static address 192.168.1.42 network 192.168.1.0 netmask 255.255.255.128 broadcast 192.168.1.0 up route add -net 192.168.1.128 netmask 255.255.255.128 gw 192.168.1.2 up route add default gw 192.168.1.200 down route del default gw 192.168.1.200 down route del -net 192.168.1.128 netmask 255.255.255.128 gw 192.168.1.2
man interfaces
中有一份更复杂的 interfaces 的配置范程:
auto lo eth0 allow-hotplug eth1 iface lo inet loopback source interfaces.d/machine-dependent mapping eth0 script /usr/local/sbin/map-scheme map HOME eth0-home map WORK eth0-work iface eth0-home inet static address 192.168.1.1 netmask 255.255.255.0 up flush-mail iface eth0-work inet dhcp iface eth1 inet dhcp
另外, DHCP能主动完成这些任务. 可用以下命令或配置:
$ dhclient eth0 # OR $ vi /etc/network/interfaces auto eth0 iface eth0 inet dhcp
etc/hosts
中是默认地址表, 其中至少需要指明localhost:
127.0.0.1 localhost 127.0.1.1 xiaopei-ThinkPad-X201
编辑/etc/hostname
可设置主机名.
less /usr/share/doc/ifupdown/examples/network-interfaces.gz
man interfaces
需确认: 默认情况下, 每新定义一个接口, ifupdown 的默认up/down脚本.
默认路由可在/etc/network/interfaces
中以gateway
指定.
静态路由是自始至终都明确不会改变的路由表项. 每条 route 命令都增加或者删除一条路由. 格式为:
$ route [op] [type] destination gw gateway [metric] [dev interface]
route del destination
route 没指定 op 的话就打印路由表, 默认会做 DNS, 可 -n 强制显示数字, 与netstat -nr
功能相同.
判断路由优先级的指标, 默认 100 , 越小越先选择
未测试
echo 200 isp2 >> /etc/iproute2/rt_tables ip rule add from <interface_IP> dev ppp0 table isp2 ip route add default via <gateway_IP> dev ppp0 table isp2
linux - Reply on same interface as incoming? - Unix and Linux
该文件是路由表 优先级 和 表名 的对应表.
# # reserved values # 255 local 254 main 253 default 0 unspec # # local # #1 inr.ruhep
除了系统默认的表外, 可添加自定义表, 之后路由规则便可按自定义表名添加. 而自定义路由表若要更换优先级, 编辑此文件便可.
# 使用前 ip rule add to 61.134.0.0/18 table 3 # 使用后 echo "3 tct" >> /etc/iproute2/rt_tables ip rule add to 66.134.0.0/18 table tct
/etc/resolv.conf
nameserver
应首先列出最近的稳定的服务器. nameserver
应该始终有不只1项, 另外最多可有3项.
/proc
文件系统是一个虚拟文件系统, 通过它可以使用一种新的方法在 Linux 内核空间和用户空间之间进行通信. 在/proc
文件系统中, 我们可以将对虚拟文件的读写作为与内核中实体进行通信的一种手段, 但是与普通文件不同的是, 这些虚拟文件的内容都是动态创建的.
联网变量都在目录/proc/sys/net
及其子目录下.
修改变量值的方法可以是:
sudo sh -c "echo 1 > /proc/sys/net/icmp_echo_ignore_broadcasts"
若要永久改变某个参数, 就要把正确的变量加到/etc/sysctl.conf
里. sysctl.conf 的文件格式是 variable=value, 变量名是相对于/proc/sys
的路径名, 如果愿意, 可以使用圆点(.)代替斜线(/). 如:
net.ipv4.ip_forward=0 net/ipv4/ip_forward=0
除非系统具有多个网络接口, 而且确实要求作为一台路由器运行, 否则建议关闭此功能. 控制文件: ipv4/ip_forward 用于整个系统, ipv4/conf/interface/forwarding 用于每个接口.
ICMP 重定向可以被恶意使用来重新路由流量, 造成路由表混乱. 建议配置路由器(以及作为路由器的主机)忽略ICMP重定向(可能的话还可以做ICMP重定向的日志记录). 控制文件: ipv4/conf/interface/accept_redirect
如果有人能够狡猾地路由一个包, 使它看起来来自于自己网络的内部而不是Internet, 就有可能跳过你的防火墙. 建议既不要接受源路由包, 也不要发送源路由包. 控制文件: ipv4/conf/interface/accept_source_route
控制文件: ipv4/icmp_echo_ignore_broadcasts