1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| 配置Linux 网络属性:ip 命令 ip – show / manipulate routing, devices, policy routingand tunnels ip [ OPTIONS ] OBJECT { COMMAND | help } OBJECT := { link | addr | route } ip link – network device configuration set dev IFACE 可设置属性: up and down :激活或禁用指定接口 ifup/ifdown show [dev IFACE] :指定接口 [up]:仅显示处于激活状态的接口 ip addr { add | del } IFADDR dev STRING [label LABEL] :添加地址时指明网卡别名 [scope {global|link|host}] :指明作用域 global: 全局可用 link: 仅链接可用 host: 本机可用 [broadcast ADDRESS] :指明广播地址 ip address show – look at protocol addresses [dev DEVICE] [label PATTERN] [primary and secondary] ip address flush – 使用格式同show ip addr add 172.16.100.100/16 dev eth0 label eth0:0 ip addr del 172.16.100.100/16 dev eth0 label eth0:0 ip addr flush dev eth0 label eth0:0 ip route – routing table management 添加路由:ip route add ip route add TARGET via GW dev IFACE src SOURCE_IP TARGET: 主机路由:IP 网络路由:NETWORK/MASK ip route add 192.168.0.0/24 via 172.16.0.1 ip route add 192.168.1.13 via 172.16.0.1 添加网关:ip route add default via GW dev IFACE ip route add default via 172.16.0.1 删除路由:ip route delete ip route del TARGET 显示路由:ip route show|list 清空路由表:ip route flush [dev IFACE] [via PREFIX] ip route flush dev eth0 例: [root@localhost ~]# ip a (显示IP地址) 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 5: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:e4:8e:e3 brd ff:ff:ff:ff:ff:ff inet 192.168.101.128/24 brd 192.168.101.255 scope global eth0 inet6 fe80::20c:29ff:fee4:8ee3/64 scope link valid_lft forever preferred_lft forever 6: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:e4:8e:ed brd ff:ff:ff:ff:ff:ff inet6 fe80::20c:29ff:fee4:8eed/64 scope link valid_lft forever preferred_lft forever [root@localhost ~]# ip link 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 5: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:e4:8e:e3 brd ff:ff:ff:ff:ff:ff 6: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:e4:8e:ed brd ff:ff:ff:ff:ff:ff [root@localhost ~]# ip addr add 9.9.9.9/24 dev eth2 添加IP地址 [root@localhost ~]# ip a eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:e4:8e:ed brd ff:ff:ff:ff:ff:ff inet 9.9.9.9/24 scope global eth2 inet6 fe80::20c:29ff:fee4:8eed/64 scope link valid_lft forever preferred_lft forever [root@localhost ~]# ip a del 9.9.9.9/24 dev eth2 [root@localhost ~]# ip a eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:e4:8e:ed brd ff:ff:ff:ff:ff:ff inet6 fe80::20c:29ff:fee4:8eed/64 scope link valid_lft forever preferred_lft forever [root@localhost ~]# ip a flush dev eth2 [root@localhost ~]# ip a eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:e4:8e:ed brd ff:ff:ff:ff:ff:ff [root@localhost ~]# service network restart Shutting down interface eth0: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: Determining IP information for eth0... done. [ OK ]
|