deb http://old-releases.ubuntu.com/ubuntu lucid main restricted universe multiverse deb http://old-releases.ubuntu.com/ubuntu lucid-security main restricted universe multiverse deb http://old-releases.ubuntu.com/ubuntu lucid-updates main restricted universe multiverse deb http://old-releases.ubuntu.com/ubuntu lucid-proposed main restricted universe multiverse deb http://old-releases.ubuntu.com/ubuntu lucid-backports main restricted universe multiverse deb-src http://old-releases.ubuntu.com/ubuntu lucid main restricted universe multiverse deb-src http://old-releases.ubuntu.com/ubuntu lucid-security main restricted universe multiverse deb-src http://old-releases.ubuntu.com/ubuntu lucid-updates main restricted universe multiverse deb-src http://old-releases.ubuntu.com/ubuntu lucid-proposed main restricted universe multiverse deb-src http://old-releases.ubuntu.com/ubuntu lucid-backports main restricted universe multiverse
48> let b = 0b110 // 二进制 b: Int = 6 49> let b = 0o11 // 八进制 b: Int = 9 50> let b = 0x11 // 十六进制
大数字表示法
1 2
53> let big = 1_000_000_000 big: Int = 1000000000
轻松显示
1 2 3 4 5 6 7 8 9 10
59> let city = "shanghai" city: String = "shanghai" 60> let food = "noodle" food: String = "noodle" 61> let restaurant = "KFC" restaurant: String = "KFC" 62> let year = 5 year: Int = 5 63> print ("When I visited \(city) \(year) years ago, I went to \(restaurant) and ordered \(food)") When I visited shanghai 5 years ago, I went to KFC and ordered noodle
# 显示网络设备 $ ip link show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000 link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff 3: eno2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 9000 qdisc mq state DOWN mode DEFAULT group default qlen 1000 link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
# 显示IP等更多信息 $ ip address show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff inet 192.168.1.123/24 brd 192.168.254.255 scope global noprefixroute eno1 valid_lft forever preferred_lft forever inet6 xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx/64 scope global noprefixroute valid_lft forever preferred_lft forever 3: eno2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 9000 qdisc mq state DOWN group default qlen 1000 link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
命令中的show为默认,也可以直接使用ip link或者ip address,结果一致。
设置IP地址
可以通过ip addr add/del xxx.xxx.xxx.xxx dev interface 来设置或者删除IP地址。
# 显示网络设备 $ ip link show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000 link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff 3: eno2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 9000 qdisc mq state DOWN mode DEFAULT group default qlen 1000 link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
# 显示IP等更多信息 $ ip address show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff inet 192.168.1.123/24 brd 192.168.254.255 scope global noprefixroute eno1 valid_lft forever preferred_lft forever inet6 xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx/64 scope global noprefixroute valid_lft forever preferred_lft forever 3: eno2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 9000 qdisc mq state DOWN group default qlen 1000 link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
命令中的show为默认,也可以直接使用ip link或者ip address,结果一致。
设置IP地址
可以通过ip addr add/del xxx.xxx.xxx.xxx dev interface 来设置或者删除IP地址。
ip link set eth0 promisc on # 开启网卡的混合模式 ip link set eth0 promisc offi # 关闭网卡的混个模式 ip link set eth0 txqueuelen 1200 # 设置网卡队列长度 ip link set eth0 mtu 1400 # 设置网卡最大传输单元 ip route show # 显示系统路由 ip route add default via 192.168.1.254 # 设置系统默认路由 ip route list # 查看路由信息 ip route add 192.168.4.0/24 via 192.168.0.254 dev eth0 # 设置192.168.4.0网段的网关为192.168.0.254,数据走eth0接口 ip route add default via 192.168.0.254 dev eth0 # 设置默认网关为192.168.0.254 ip route del 192.168.4.0/24 # 删除192.168.4.0网段的网关 ip route del default # 删除默认路由 ip route delete 192.168.1.0/24 dev eth0 # 删除路由
用 ip 命令显示网络设备的运行状态:
1 2 3 4 5 6 7
[root@localhost~]# ip link list 1: lo:<LOOPBACK,UP,LOWER_UP>mtu16436qdiscnoqueue link/loopback00:00:00:00:00:00brd00:00:00:00:00:00 2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP>mtu1500 qdiscpfifo_fastqlen1000 link/ether00:16:3e:00:1e:51brdff:ff:ff:ff:ff:ff 3: eth1:<BROADCAST,MULTICAST,UP,LOWER_UP>mtu1500 qdiscpfifo_fastqlen1000 link/ether00:16:3e:00:1e:52brdff:ff:ff:ff:ff:ff
显示核心路由表:
1 2 3 4 5 6 7
[root@localhost ~]# ip route list 112.124.12.0/22 dev eth1 proto kernel scope link src 112.124.15.130 10.160.0.0/20 dev eth0 proto kernel scope link src 10.160.7.81 192.168.0.0/16 via 10.160.15.247 dev eth0 172.16.0.0/12 via 10.160.15.247 dev eth0 10.0.0.0/8 via 10.160.15.247 dev eth0 default via 112.124.15.247 dev eth1
显示邻居表:
1 2 3
[root@localhost ~]# ip neigh list 112.124.15.247 dev eth1 lladdr 00:00:0c:9f:f3:88 REACHABLE 10.160.15.247 dev eth0 lladdr 00:00:0c:9f:f2:c0 STALE
获取主机所有网络接口炫技:
1
ip link | grep -E '^[0-9]' | awk -F: '{print $2}'
-h, -human, -human-readable
output statistics with human readable values followed by suffix.
-b, -batch <FILENAME>
Read commands from provided file or standard input and invoke them. First failure will cause termination of ip.
-force Don't terminate ip on errors in batch mode. If there were any errors during execution of the commands, the application return code will be non zero.
-d, -details Output more detailed information.
-l, -loops <COUNT>
Specify maximum number of loops the 'ip address flush' logic will attempt before giving up. The default is 10. Zero (0) means loop until all addresses are
removed.
-f, -family <FAMILY>
Specifies the protocol family to use. The protocol family identifier can be one of inet, inet6, bridge, ipx, dnet, mpls or link. If this option is not present,
the protocol family is guessed from other arguments. If the rest of the command line does not give enough information to guess the family, ip falls back to the
default one, usually inet or any. link is a special family identifier meaning that no networking protocol is involved.
-o, -oneline output each record on a single line, replacing line feeds with the ‘' character. This is convenient when you want to count records with wc(1) or to grep(1) the output. -r, -resolve use the system’s name resolver to print DNS names instead of host addresses.
-n, -netns switches ip to the specified network namespace NETNS. Actually it just simplifies executing of: ip netns exec NETNS ip [ OPTIONS ] OBJECT { COMMAND | help }
to
ip -n[etns] NETNS [ OPTIONS ] OBJECT { COMMAND | help }
-a, -all
executes specified command over all objects, it depends if command supports this option.
-c, -color
Use color output.
-t, -timestamp
display current time when using monitor option.
-ts, -tshort
Like -timestamp, but use shorter format.
-rc, -rcvbuf<SIZE>
Set the netlink socket receive buffer size, defaults to 1MB.
-iec print human readable rates in IEC units (e.g. 1Ki = 1024).
IP - COMMAND SYNTAX
OBJECT
addrlabel
- label configuration for protocol address selection.
l2tp - tunnel ethernet over IP (L2TPv3).
maddress
- multicast address.
monitor
- watch for netlink messages.
mroute - multicast routing cache entry.
mrule - rule in multicast routing policy database.
neighbour
- manage ARP or NDISC cache entries.
netns - manage network namespaces.
ntable - manage the neighbor cache's operation.
tcp_metrics/tcpmetrics
- manage TCP Metrics
token - manage tokenized interface identifiers.
tunnel - tunnel over IP.
tuntap - manage TUN/TAP devices.
xfrm - manage IPSec policies.
The names of all objects may be written in full or abbreviated form, for example address can be abbreviated as addr or just a.