根据IP查网卡地址
arping IP地址
根据IP查电脑名
nmblookup -A IP地址
查看当前IP地址
ifconfig eth0 |awk '/inet/ {split($2,x,":");print x[2]}'
查看当前外网的IP地址
w3m -no-cookie -dump www.ip138.com/ip2city.asp|grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' w3m -no-cookie -dump ip.loveroot.com|grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' curl ifconfig.me
查看当前监听80端口的程序
lsof -i :80
查看当前网卡的物理地址
ifconfig eth0 | head -1 | awk '{print $5}'
同一个网卡增加第二个IP地址
#在网卡eth0上增加一个1.2.3.4的IP: sudo ifconfig eth0:0 1.2.3.4 netmask 255.255.255.0 #删除增加的IP: sudo ifconfig eth0:0 down
立即让网络支持nat
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward sudo iptables -t nat -I POSTROUTING -j MASQUERADE
查看路由信息
netstat -rn sudo route -n
手工增加一条路由
sudo route add -net 192.168.0.0 netmask 255.255.255.0 gw 172.16.0.1
手工删除一条路由
sudo route del -net 192.168.0.0 netmask 255.255.255.0 gw 172.16.0.1
修改网卡MAC地址的方法
sudo ifconfig eth0 down #关闭网卡 sudo ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE #然后改地址 sudo ifconfig eth0 up #然后启动网卡
永久改地址方法
sudo gedit /etc/network/interfaces
在 iface eth0 inet static 后面添加一行:
pre-up ifconfig eth0 hw ether 01:01:01:01:01:01
配置文件应该像如下
iface eth0 inet static pre-up ifconfig eth0 hw ether 01:01:01:01:01:01 address 192.168.1.10 netmask 255.255.255.0 gateway 192.168.1.1
最后是 logout 或者reboot
统计当前IP连接的个数
netstat -na|grep ESTABLISHED|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -r -n netstat -na|grep SYN|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -r -n netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
统计当前所有IP包的状态
netstat -nat|awk '{print awk $NF}'|sort|uniq -c|sort -n
统计当前20000个IP包中大于100个IP包的IP地址
tcpdump -tnn -c 20000 -i eth0 | awk -F "." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr | awk ' $1 > 100 '
屏蔽IPV6
echo "blacklist ipv6" | sudo tee /etc/modprobe.d/blacklist-ipv6
察看当前网络连接状况以及程序
sudo netstat -atnp
查看网络连接状态
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
查看当前系统所有的监听端口
nc -zv localhost 1-65535
查看网络的当前流量
#安装 ethstatus 软件 sudo apt-get install ethstatus #查看 ADSL 的速度 sudo ethstatus -i ppp0 #查看 网卡 的速度 sudo ethstatus -i eth0 #或安装 bwm-ng sudo apt-get install bwm-ng #查看当前网络流量 bwm-ng
查看域名的注册备案情况
whois baidu.cn
查看到某一个域名的路由情况
tracepath baidu.cn
重新从服务器获得IP地址
sudo dhclient
从当前页面开始镜像整个网站到本地
wget -r -p -np -k http://www.21cn.com · -r:在本机建立服务器端目录结构; · -p: 下载显示HTML文件的所有图片; · -np:只下载目标站点指定目录及其子目录的内容; · -k: 转换非相对链接为相对链接。
如何多线程下载
sudo apt-get install axel axel -n 5 http://xxx.xxx.xxx.xxx/xxx.zip 或者 lftp -c "pget -n 5 http://xxx.xxx.xxx.xxx/xxx.zip“
如何查看HTTP头
w3m -dump_head http://www.example.com 或 curl --head http://www.example.com
快速使用http方式共享目录
#进入需要共享的目录后运行: python -m SimpleHTTPServer #其它电脑使用http://ip:8000 来访问 #自定义端口为8080: python -m SimpleHTTPServer 8080
SSH 远程端口转发
ssh -v -CNgD 7070 username@sshhostipaddress
监控网络所有的tcp数据
sudo apt-get install snort #安装snort入侵检测程序 sudo snort -vde
监控TCP/UDP连接的流量
sudo apt-get install iftop sudo iftop #或 sudo apt-get install iptraf sudo iptraf
iptables
防止外网用内网IP欺骗
#eth0 为外网网卡 sudo iptables -t nat -A PREROUTING -i eth0 -s 10.0.0.0/8 -j DROP sudo iptables -t nat -A PREROUTING -i eth0 -s 172.16.0.0/12 -j DROP sudo iptables -t nat -A PREROUTING -i eth0 -s 192.168.0.0/16 -j DROP
查看nat规则
sudo iptables -t nat -L
查看filter规则
sudo iptables -L -n
取消nat规则
sudo iptables -t nat -F
取消filter规则
sudo iptables -F
阻止一个IP连接本机
#规则位于最后 sudo iptables -t filter -A INPUT -s 192.168.1.125 -i eth0 -j DROP
关闭 1234 端口
sudo iptables -A OUTPUT -p tcp --dport 1234 -j DROP
开启 80 端口
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
限制访问80端口的外部IP最大只有50个并发
sudo iptables -A INPUT -p tcp --dport 80 -m connlimit --connlimit-above 50 --connlimit-mask 32 -j DROP
禁止一个IP或者一个IP段访问服务器端口服务
#80端口 ,规则插入到前面 sudo iptables -t filter -I INPUT -s 192.168.2.0/24 -p tcp --dport http -j DROP #21端口,规则插入到前面 sudo iptables -t filter -I INPUT -s 192.168.1.23 -p tcp --dport ftp -j DROP