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.AFpython

網絡
根據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
相關文章
相關標籤/搜索