ubuntu 命令学习大全

http://wiki.ubuntu.org.cn/UbuntuSkills#.E6.98.BE.E7.A4.BA.E5.BD.93.E5.89.8D.E7.A1.AC.E4.BB.B6.E4.BF.A1.E6.81.AF

网络
根据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
立即让网络支持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
扫描某个IP的端口
nc -v -w 1 192.168.1.1 -z 1-1000

 

posted on 2016-07-01 11:02  星空守望者--jkmiao  阅读(769)  评论(0编辑  收藏  举报