ubuntu全面教程适合新手:四

Linux 系统中如何限制用户进程 CPU 占用率

renice +10 `ps aux | awk '{ if ($3 > 0.8 && id -u $1 > 500) print $2}'`
#或直接编辑/etc/security/limits.conf 文件

ADSL
配置 ADSL

sudo pppoeconf

ADSL 手工拨号

sudo pon dsl-provider

激活 ADSL

sudo /etc/ppp/pppoe_on_boot

断开 ADSL

sudo poff

查看拨号日志

sudo plog

如何设置动态域名

#首先去 http://www.3322.org 申请一个动态域名
#然後修改 /etc/ppp/ip-up 增加拨号时更新域名指令
sudo vim /etc/ppp/ip-up
#在最後增加如下行
w3m -no-cookie -dump 'http://username:password@members.3322.org/dyndns/update?system=dyndns&hostname=yourdns.3322.org'

网络
根据 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

连接下文:http://www.ubuntukylin.com/ukyli … ead&tid=4582&extra=