Linux常用网络命令

来源:互联网 发布:深圳岂凡网络 林秋敏 编辑:程序博客网 时间:2024/06/07 15:13
转自:http://www.cnblogs.com/jkmiao/p/5632355.html
网络根据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}'或者cat /sys/class/net/eth0/address同一个网卡增加第二个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立即让网络支持natecho 1 | sudo tee /proc/sys/net/ipv4/ip_forwardsudo iptables -t nat -I POSTROUTING -j MASQUERADE查看路由信息netstat -rnsudo 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 staticpre-up ifconfig eth0 hw ether 01:01:01:01:01:01address 192.168.1.10netmask 255.255.255.0gateway 192.168.1.1最后是 logout 或者reboot统计当前IP连接的个数netstat -na|grep ESTABLISHED|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -r -nnetstat -na|grep SYN|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -r -nnetstat -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 '屏蔽IPV6echo "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 axelaxel -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 8080SSH 远程端口转发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 iptrafsudo iptraf扫描某个IP的端口nc -v -w 1 192.168.1.1 -z 1-1000
原创粉丝点击