Skip to content

Commit 9c31dca

Browse files
committed
add ethtool usage and group other command usage.
1 parent ac00ff3 commit 9c31dca

File tree

1 file changed

+74
-55
lines changed

1 file changed

+74
-55
lines changed

bashrc/oneline_cmd

Lines changed: 74 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# one line cmd for static state of tcp/ip.
2-
netstat -pant | awk '/^tcp/ {++state[$6]} END {for(key in state) printf("%-10s\t%d\n", key,state[key])}'
3-
1+
################## networking ##################
42
# system route table
53
# Routing tables
64
#
@@ -29,36 +27,27 @@ netstat -pant | awk '/^tcp/ {++state[$6]} END {for(key in state) printf("%-10s\t
2927
# D Route was created dynamically or by ICMP redirect;
3028
netstat -nr
3129

32-
# one line cmd display dir file.
33-
ls -lR | grep -v total | awk 'BEGIN { OFS="\t"; ORS="\n-->"} {print $1,$3,$NF}'
34-
35-
# find failure of soft links
36-
find . -type l | perl -lne 'print if ! -e'
37-
38-
# sort filename by column 1
39-
sort -k1,1n filename
40-
41-
#static memory for process
42-
ps -eo fname,rss | awk '{arr[$1]+=$2} END {for (i in arr) {print i,arr[i]}}' | sort -k2 -nr | column -t
43-
44-
# one line cmd display tcp/ip info.
45-
ss --options --extended --memory --processes --info
46-
ss -an | grep "TIME-WAIT" | awk '{print $NF}' | grep -P "^(\d+\.){3}(\d+):\d+$" | grep -oP "(\d+\.){3}(\d+)" | sort | uniq -c
47-
ss --info sport = :2112 dport = :4057
48-
ss -tan 'sport = :80' | awk '{print $(NF)" "$(NF-1)}' | sed 's/:[^ ]*//g' | sort | uniq -c
49-
50-
#ifconfig
51-
ifconfig eth0 mtu 1500
52-
ifconfig eth0 down
53-
ifconfig eth0 up
54-
5530
# display network and route
5631
ip route show
5732
ip ro add 10.0.0.0/8 via 10.11.11.254
5833

5934
#config initcwnd and initrwnd
6035
ip route | while read p; do echo "ip route change $p initcwnd 10 initrwnd 10"; done
6136

37+
#iptables
38+
#iptables [-t table] command [match] [target/jump]
39+
# -t --table: table(filter, nat, mangle, raw)
40+
# -A -D -I -R: chain -L,--lsit,-F,--flush,-Z,-N,-X,-P,-E
41+
# match regx: tcp,udp,icmp,limit,mac,mark,owner,state,tos,ttl
42+
# -j target:(ACCEPT, DROP, REJECT)
43+
iptables -A INPUT -p tcp --dport 80 -m time --timestart 09:00 --timestop 18:00 -j DROP
44+
iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 22 -j ACCEPT
45+
iptables -t filter -A INPUT -s 192.168.1.1 -j DROP
46+
47+
#------------- network monitoring --------------
48+
#iptraf | tcpdump | tcpflow | ss | netstat
49+
iptraf
50+
6251
#tcpdump
6352
#tcpdump [ -AdDeflLnNOpqRStuUvxX ] [ -c count ]
6453
# [ -C file_size ] [ -F file ]
@@ -79,15 +68,65 @@ tcpdump -nnvXSs 0 -c2 icmp
7968
#tcpflow
8069
tcpflow -cp -i eth0 "port 80"
8170

82-
#iptables
83-
#iptables [-t table] command [match] [target/jump]
84-
# -t --table: table(filter, nat, mangle, raw)
85-
# -A -D -I -R: chain -L,--lsit,-F,--flush,-Z,-N,-X,-P,-E
86-
# match regx: tcp,udp,icmp,limit,mac,mark,owner,state,tos,ttl
87-
# -j target:(ACCEPT, DROP, REJECT)
88-
iptables -A INPUT -p tcp --dport 80 -m time --timestart 09:00 --timestop 18:00 -j DROP
89-
iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 22 -j ACCEPT
90-
iptables -t filter -A INPUT -s 192.168.1.1 -j DROP
71+
# one line cmd display tcp/ip info.
72+
ss --options --extended --memory --processes --info
73+
ss -an | grep "TIME-WAIT" | awk '{print $NF}' | grep -P "^(\d+\.){3}(\d+):\d+$" | grep -oP "(\d+\.){3}(\d+)" | sort | uniq -c
74+
ss --info sport = :2112 dport = :4057
75+
ss -tan 'sport = :80' | awk '{print $(NF)" "$(NF-1)}' | sed 's/:[^ ]*//g' | sort | uniq -c
76+
77+
# one line cmd for static state of tcp/ip.
78+
netstat -tanl
79+
netstat -pant | awk '/^tcp/ {++state[$6]} END {for(key in state) printf("%-10s\t%d\n", key,state[key])}'
80+
81+
#check smp_affinity:
82+
# Ethernet controller
83+
# MSI-X: Enable+ Count=9 Masked- (Enable+ and Count > 1)
84+
lspci -vvv | less
85+
86+
#check ring buffer
87+
ethtool -g eth0
88+
#check net interface offloading
89+
ethtool -k eth0 #look option
90+
ethtool -K eth0 tso off #set option
91+
92+
#ifconfig
93+
ifconfig eth0 mtu 1500
94+
ifconfig eth0 down
95+
ifconfig eth0 up
96+
97+
################## kernel compile ##################
98+
# BIOS -> MBR
99+
# grub -> kernel(bzImage) /boot/vmlinuz-3.2.0-74-generic-pae
100+
# -> initrd.img /boot/initrd.img-3.2.0-74-generic-pae
101+
# initrd.img: some drivers and kernel module
102+
#### compile a new kernel from source code
103+
#get a template .config file
104+
cp config-3.2.0-74-generic-pae .config
105+
#run make menuconfig need some package: ncurses-devel
106+
#(ubuntu:sudo apt-get install libncurses5-dev)
107+
#modify the .config file
108+
make menuconfig
109+
#compile the kernel
110+
make bzImage
111+
#compile the modules
112+
make modules
113+
make modules_install
114+
#install kernel: cp arch/i386/boot/bzImage /boot/vmlinuz-xxx && mkinitrd /boot/initrd-xxx.img xxx && vi /boot/grub/grub.conf
115+
make install
116+
117+
118+
############# command ##################
119+
# one line cmd display dir file.
120+
ls -lR | grep -v total | awk 'BEGIN { OFS="\t"; ORS="\n-->"} {print $1,$3,$NF}'
121+
122+
# find failure of soft links
123+
find . -type l | perl -lne 'print if ! -e'
124+
125+
# sort filename by column 1
126+
sort -k1,1n filename
127+
128+
#static memory for process
129+
ps -eo fname,rss | awk '{arr[$1]+=$2} END {for (i in arr) {print i,arr[i]}}' | sort -k2 -nr | column -t
91130

92131
#RAID0
93132
mdadm -C /dev/md0 -a yes -l 0 -n 2 /dev/sdb /dev/sdc
@@ -117,25 +156,6 @@ slabtop -o | grep -E '(^ OBJS|tw_sock_TCP|tcp_bind_bucket)'
117156
#trace network syscall for a existed PID.
118157
strace -p $PID -f -e trace=network -s 10000
119158

120-
# BIOS -> MBR
121-
# grub -> kernel(bzImage) /boot/vmlinuz-3.2.0-74-generic-pae
122-
# -> initrd.img /boot/initrd.img-3.2.0-74-generic-pae
123-
# initrd.img: some drivers and kernel module
124-
#### compile a new kernel from source code
125-
#get a template .config file
126-
cp config-3.2.0-74-generic-pae .config
127-
#run make menuconfig need some package: ncurses-devel
128-
#(ubuntu:sudo apt-get install libncurses5-dev)
129-
#modify the .config file
130-
make menuconfig
131-
#compile the kernel
132-
make bzImage
133-
#compile the modules
134-
make modules
135-
make modules_install
136-
#install kernel: cp arch/i386/boot/bzImage /boot/vmlinuz-xxx && mkinitrd /boot/initrd-xxx.img xxx && vi /boot/grub/grub.conf
137-
make install
138-
139159
tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]"
140160
#display one line '#' with screen width
141161
printf "%`tput cols`s" | tr ' ' '#'
@@ -148,7 +168,6 @@ pip install django --index-url http://pypi.douban.com/simple
148168
# (?<=exp) post match
149169
# (?<!exp) post not match
150170
# regx (?<=<(\w+)>).*(?=<\/\1>) for html tag
151-
152171
# checks to [192.168.32.208]: host [32.208 xuebao] not found
153172
# match [xxx] and [xxx] content.
154173
grep -Po '(?<=\[)[^]]+'

0 commit comments

Comments
 (0)