1、连接上相应的linux主机,进入到等待输入shell指令的linux命令行状态下。
B. Linux绯荤粺镆ョ湅IP鍦板潃 IP璁剧疆涓庢煡鐪嫔懡浠ゅぇ鍏
Linux鏄涓绉嶈嚜鐢卞拰寮鏀炬簮镰佺殑绫箓nix镎崭綔绯荤粺锛屽瓨鍦ㄧ潃璁稿氢笉钖岀殑Linux鐗堟湰锛屼絾瀹冧滑閮戒娇鐢ㄤ简Linux鍐呮牳锛屽湪寰埚氢笓涓氲$畻链哄満钖堥兘链夌敤鍒般侺inux镎崭綔绯荤粺浣跨敤鐩稿硅缉涓哄嶆潅锛岀敱浜庨氩父閮芥槸锻戒护镎崭綔锛屾瘆鎴戜滑镡熺煡镄刉inodows绯荤粺镟翠笉瀹规槗涓婃坠锛屼絾鍏跺畨鍏ㄦу嵈瑕佹洿楂桡纴阍埚归渶瑕佽剧疆Linux绯荤粺缃戠粶镄勬湅鍙嬶纴浠ヤ笅锏句簨缃戝皬缂栦负鍏堕梼涓妉inux绯荤粺IP璁剧疆涓庢煡鐪嫔懡浠ゅぇ鍏锛屽笇链涘规柊镓嬫湅鍙嬫湁镓甯锷┿
1. 浣跨敤ifconfig锻戒护閰岖疆骞舵煡鐪嬬绣缁沧帴鍙f儏鍐电ず渚1: 閰岖疆eth0镄処P锛屽悓镞舵縺娲昏惧:# ifconfig eth0 192.168.4.1 netmask 255.255.255.0 up绀轰緥2: 閰岖疆eth0鍒钖嶈惧 eth0:1 镄処P锛屽苟娣诲姞璺鐢# ifconfig eth0:1 192.168.4.2# route add 钬揾ost 192.168.4.2 dev eth0:1绀轰緥3:婵娲伙纸绂佺敤锛夎惧# ifconfig eth0:1 up(down)绀轰緥4:镆ョ湅镓链夛纸鎸囧畾锛夌绣缁沧帴鍙i厤缃# ifconfig (eth0)钬斺斺斺斺斺斺斺斺2. 浣跨敤route 锻戒护閰岖疆璺鐢辫〃绀轰緥1:娣诲姞鍒颁富链鸿矾鐢# route add 钬揾ost 192.168.4.2 dev eth0:1# route add 钬揾ost 192.168.4.1 gw 192.168.4.250绀轰緥2:娣诲姞鍒扮绣缁灭殑璺鐢# route add 钬搉et IP netmask MASK eth0# route add 钬搉et IP netmask MASK gw IP# route add 钬搉et IP/24 eth1绀轰緥3:娣诲姞榛樿ょ绣鍏# route add default gw IP绀轰緥4:鍒犻櫎璺鐢# route del 钬揾ost 192.168.4.1 dev eth0:1绀轰緥5:镆ョ湅璺鐢变俊鎭#route 鎴杛oute -n(-n 琛ㄧず涓嶈В鏋愬悕瀛,鍒楀嚭阃熷害浼氭瘆route 蹇)钬斺斺斺斺斺斺斺斺3.ARP 绠$悊锻戒护绀轰緥1:镆ョ湅ARP缂揿瓨# arp绀轰緥2:娣诲姞# arp 钬搒 IP MAC绀轰緥3: 鍒犻櫎# arp 钬揹 IP钬斺斺斺斺斺斺斺斺4.ip鏄痠proute2杞浠跺寘閲岄溃镄勪竴涓寮哄ぇ镄勭绣缁滈厤缃宸ュ叿锛屽畠鑳藉熸浛浠d竴浜涗紶缁熺殑缃戠粶绠$悊宸ュ叿銆备緥濡傦细ifconfig銆乺oute绛,涓婇溃镄勭ず渚嫔畬鍏ㄥ彲浠ョ敤涓嬮溃镄刬p锻戒护瀹炵幇,钥屼笖ip锻戒护鍙浠ュ疄鐜版洿澶氱殑锷熻兘.涓嬮溃浠嬬粛涓浜涚ず渚:
4.0 ip锻戒护镄勮娉昳p [OPTIONS] OBJECT [COMMAND [ARGUMENTS]]
4.1 ip link set钬撴敼鍙樿惧囩殑灞炴.缂╁啓锛歴et銆乻
绀轰緥1锛歶p/down 璧峰姩锛忓叧闂璁惧囥# ip link set dev eth0 up杩欎釜绛変簬浼犵粺镄 # ifconfig eth0 up(down)绀轰緥2锛氭敼鍙樿惧囦紶杈挞槦鍒楃殑闀垮害銆傚弬鏁:txqueuelen NUMBER鎴栬卼xqlen NUMBER# ip link set dev eth0 txqueuelen 100绀轰緥3锛氭敼鍙樼绣缁滆惧嘙TU(链澶т紶杈揿崟鍏)镄勫笺# ip link set dev eth0 mtu 1500绀轰緥4锛 淇鏀圭绣缁滆惧囩殑MAC鍦板潃銆傚弬鏁: address LLADDRESS# ip link set dev eth0 address 00:01:4f:00:15:f1
4.2 ip link show钬撴樉绀鸿惧囧睘镐.缂╁啓锛歴how銆乴ist銆乴st銆乻h銆乴s銆乴-s阃夐”鍑虹幇涓ゆ℃垨钥呮洿澶氭★纴ip浼氲緭鍑烘洿涓鸿︾粏镄勯敊璇淇℃伅缁熻°傜ず渚:# ip -s -s link ls eth0杩欎釜锻戒护绛変簬浼犵粺镄 ifconfig eth0钬斺斺斺斺斺斺斺斺5.1 ip address add钬撴坊锷犱竴涓鏂扮殑鍗忚鍦板潃. 缂╁啓锛歛dd銆乤绀轰緥1锛氢负姣忎釜鍦板潃璁剧疆涓涓瀛楃︿覆浣滀负镙囩俱备负浜嗗拰Linux-2.0镄勭绣缁滃埆钖嶅吋瀹癸纴杩欎釜瀛楃︿覆蹇呴’浠ヨ惧囧悕寮澶达纴鎺ョ潃涓涓鍐掑彿锛# ip addr add local 192.168.4.1/28 brd + label eth0:1 dev eth0绀轰緥2: 鍦ㄤ互澶缃戞帴鍙eth0涓婂炲姞涓涓鍦板潃192.168.20.0锛屾帺镰侀暱搴︿负24浣(155.155.155.0)锛屾爣鍑嗗箍鎾鍦板潃锛屾爣绛句负eth0:Alias锛# ip addr add 192.168.4.2/24 brd + dev eth1 label eth1:1杩欎釜锻戒护绛変簬浼犵粺镄:ifconfig eth1:1 192.168.4.2
5.2 ip address delete钬揿垹闄や竴涓鍗忚鍦板潃. 缂╁啓锛歞elete銆乨el銆乨# ip addr del 192.168.4.1/24 brd + dev eth0 label eth0:Alias1
5.3 ip address show钬撴樉绀哄岗璁鍦板潃. 缂╁啓锛歴how銆乴ist銆乴st銆乻h銆乴s銆乴# ip addr ls eth0
5.4.ip address flush钬撴竻闄ゅ岗璁鍦板潃. 缂╁啓锛歠lush銆乫绀轰緥1 : 鍒犻櫎灞炰簬绉佺绣10.0.0.0/8镄勬墍链夊湴鍧锛# ip -s -s a f to 10/8绀轰緥2 : 鍙栨秷镓链変互澶缃戝崱镄処P鍦板潃# ip -4 addr flush label 钬渆th0钬斥斺斺斺斺斺斺斺斺6. ip neighbour钬搉eighbour/arp琛ㄧ$悊锻戒护缂╁啓 neighbour銆乶eighbor銆乶eigh銆乶锻戒护 add銆乧hange銆乺eplace銆乨elete銆乫ulsh銆乻how(鎴栬卨ist)
6.1 ip neighbour add 钬 娣诲姞涓涓鏂扮殑闾绘帴𨱒$洰ip neighbour change钬扑慨鏀逛竴涓鐜版湁镄勬浔鐩甶p neighbour replace钬撴浛鎹涓涓宸叉湁镄勬浔鐩缂╁啓锛歛dd銆乤锛沜hange銆乧hg锛况eplace銆乺epl绀轰緥1: 鍦ㄨ惧噀th0涓婏纴涓哄湴鍧10.0.0.3娣诲姞涓涓猵ermanent ARP𨱒$洰锛# ip neigh add 10.0.0.3 lladdr 0:0:0:0:0:1 dev eth0 nud perm绀轰緥2:鎶婄姸镐佹敼涓簉eachable# ip neigh chg 10.0.0.3 dev eth0 nud reachable
6.2.ip neighbour delete钬揿垹闄や竴涓闾绘帴𨱒$洰绀轰緥1:鍒犻櫎璁惧噀th0涓婄殑涓涓狝RP𨱒$洰10.0.0.3# ip neigh del 10.0.0.3 dev eth06.3.ip neighbour show钬撴樉绀虹绣缁滈偦灞呯殑淇℃伅.缂╁啓锛歴how銆乴ist銆乻h銆乴s绀轰緥1: # ip -s n ls 193.233.7.254193.233.7.254. dev eth0 lladdr 00:00:0c:76:3f:85 ref 5 used 12/13/20 nud reachable6.4.ip neighbour flush钬撴竻闄ら偦鎺ユ浔鐩. 缂╁啓锛歠lush銆乫绀轰緥1: (-s 鍙浠ユ樉绀鸿︾粏淇℃伅)# ip -s -s n f 193.233.7.254钬斺斺斺斺斺斺斺斺7. 璺鐢辫〃绠$悊7.1.缂╁啓 route銆乺o銆乺7.5.璺鐢辫〃浠嶭inux-2.2寮濮嬶纴鍐呮牳鎶婅矾鐢卞綊绾冲埌璁稿氲矾鐢辫〃涓锛岃繖浜涜〃閮借繘琛屼简缂栧彿锛岀紪鍙锋暟瀛楃殑锣冨洿鏄1鍒255銆傚彟澶栵纴涓轰简鏂逛究锛岃缮鍙浠ュ湪/etc/iproute2/rt_tables涓涓鸿矾鐢辫〃锻藉悕銆傞粯璁ゆ儏鍐典笅锛屾墍链夌殑璺鐢遍兘浼氲鎻掑叆鍒拌〃main(缂栧彿254)涓銆傚湪杩涜岃矾鐢辨煡璇㈡椂锛屽唴镙稿彧浣跨敤璺鐢辫〃main銆
7.6.ip route add 钬 娣诲姞鏂拌矾鐢眎p route change 钬 淇鏀硅矾鐢眎p route replace 钬 镟挎崲宸叉湁镄勮矾鐢辩缉鍐欙细add銆乤锛沜hange銆乧hg锛况eplace銆乺epl绀轰緥1: 璁剧疆鍒扮绣缁10.0.0/24镄勮矾鐢辩粡杩囩绣鍏193.233.7.65# ip route add 10.0.0/24 via 193.233.7.65
绀轰緥2: 淇鏀瑰埌缃戠粶10.0.0/24镄勭洿鎺ヨ矾鐢憋纴浣垮叾缁忚繃璁惧嘾ummy# ip route chg 10.0.0/24 dev mmy
绀轰緥3: 瀹炵幇阈捐矾璐熻浇骞宠.锷犲叆缂虹渷澶氲矾寰勮矾鐢憋纴璁﹑pp0鍜宲pp1鍒嗘媴璐熻浇(娉ㄦ剰锛歴cope鍊煎苟闱炲繀闇锛屽畠鍙涓嶈繃鏄锻婅瘔鍐呮牳锛岃繖涓璺鐢辫佺粡杩囩绣鍏宠屼笉鏄鐩磋繛镄勚傚疄闄呬笂锛屽傛灉浣犵煡阆撹繙绋嬬镣圭殑鍦板潃锛屼娇鐢╲ia鍙傛暟𨱒ヨ剧疆灏辨洿濂戒简)銆# ip route add default scope global nexthop dev ppp0 nexthop dev ppp1# ip route replace default scope global nexthop dev ppp0 nexthop dev ppp1绀轰緥4: 璁剧疆NAT璺鐢便傚湪杞鍙戞潵镊192.203.80.144镄勬暟鎹鍖呬箣鍓嶏纴鍏堣繘琛岀绣缁滃湴鍧杞鎹锛屾妸杩欎釜鍦板潃杞鎹涓193.233.7.83# ip route add nat 192.203.80.142 via 193.233.7.83
绀轰緥5: 瀹炵幇鏁版嵁鍖呯骇璐熻浇骞宠,鍏佽告妸鏁版嵁鍖呴殢链轰粠澶氢釜璺鐢卞彂鍑恒倃eight 鍙浠ヨ剧疆𨱒冮吨.# ip route replace default equalize nexthop via 211.139.218.145 dev eth0 weight 1 nexthop via 211.139.218.145 dev eth1 weight 1
7.7.ip route delete钬 鍒犻櫎璺鐢辩缉鍐欙细delete銆乨el銆乨绀轰緥1:鍒犻櫎涓娄竴鑺傚懡浠ゅ姞鍏ョ殑澶氲矾寰勮矾鐢# ip route del default scope global nexthop dev ppp0 nexthop dev ppp1
7.8.ip route show 钬 鍒楀嚭璺鐢辩缉鍐欙细show銆乴ist銆乻h銆乴s銆乴
绀轰緥1: 璁$畻浣跨敤gated/bgp鍗忚镄勮矾鐢变釜鏁# ip route ls proto gated/bgp |wc1413989179010
绀轰緥2: 璁$畻璺鐢辩紦瀛橀噷闱㈢殑𨱒℃暟锛岀敱浜庤缂揿瓨璺鐢辩殑灞炴у彲鑳藉ぇ浜庝竴琛岋纴浠ユら渶瑕佷娇鐢-o阃夐”# ip -o route ls cloned |wc159254318707绀轰緥3: 鍒楀嚭璺鐢辫〃TABLEID閲岄溃镄勮矾鐢便傜己鐪佽剧疆鏄痶able main銆俆ABLEID鎴栬呮槸涓涓鐪熸g殑璺鐢辫〃ID鎴栬呮槸/etc/iproute2/rt_tables鏂囦欢瀹氢箟镄勫瓧绗︿覆锛屾垨钥呮槸浠ヤ笅镄勭壒娈婂硷细all 钬 鍒楀嚭镓链夎〃镄勮矾鐢憋绂cache 钬 鍒楀嚭璺鐢辩紦瀛樼殑鍐呭广俰p ro ls 193.233.7.82 tab cache绀轰緥4: 鍒楀嚭镆愪釜璺鐢辫〃镄勫唴瀹# ip route ls table fddi153
绀轰緥5: 鍒楀嚭榛樿よ矾鐢辫〃镄勫唴瀹# ip route ls杩欎釜锻戒护绛変簬浼犵粺镄: route
7.9.ip route flush 钬 镎﹂櫎璺鐢辫〃绀轰緥1: 鍒犻櫎璺鐢辫〃main涓镄勬墍链夌绣鍏宠矾鐢憋纸绀轰緥锛氩湪璺鐢辩洃鎺х▼搴忔寕鎺変箣钖庯级锛# ip -4 ro flush scope global type unicast绀轰緥2:娓呴櫎镓链夎鍏嬮殕鍑烘潵镄処Pv6璺鐢憋细# ip -6 -s -s ro flush cache绀轰緥3:鍦╣ated绋嫔簭鎸傛帀涔嫔悗锛屾竻闄ゆ墍链夌殑BGP璺鐢憋细# ip -s ro f proto gated/bgp绀轰緥4: 娓呴櫎镓链塱pv4璺鐢眂ache# ip route flush cache*** IPv4 routing cache is flushed.
7.10ip route get 钬 銮峰缑鍗曚釜璺鐢 .缂╁啓锛欢et銆乬浣跨敤杩欎釜锻戒护鍙浠ヨ幏寰楀埌杈剧洰镄勫湴鍧镄勪竴涓璺鐢变互鍙婂畠镄勭‘鍒囧唴瀹广俰p route get锻戒护鍜宨p route show锻戒护镓ц岀殑镎崭綔鏄涓嶅悓镄勚俰p route show锻戒护鍙鏄鏄剧ず鐜版湁镄勮矾鐢憋纴钥宨p route get锻戒护鍦ㄥ繀瑕佹椂浼氭淳鐢熷嚭鏂扮殑璺鐢便傜ず渚1: 鎼灭储鍒193.233.7.82镄勮矾鐢# ip route get 193.233.7.82193.233.7.82 dev eth0src 193.233.7.65 realms inr.ac cachemtu 1500 rtt 300绀轰緥2: 鎼灭储鐩镄勫湴鍧鏄193.233.7.82锛屾潵镊193.233.7.82锛屼粠eth0璁惧囧埌杈剧殑璺鐢憋纸杩欐浔锻戒护浼氢骇鐢熶竴𨱒¢潪甯告湁镒忔濈殑璺鐢憋纴杩欐槸涓𨱒″埌193.233.7.82镄勫洖鐜璺鐢憋级# ip r g 193.233.7.82 from 193.233.7.82 iif eth0193.233.7.82 from 193.233.7.82 dev eth0src 193.233.7.65realms inr.ac/inr.accache ;mtu 1500 rtt 300 iif eth0钬斺斺斺斺斺斺斺斺8. ip route 钬 璺鐢辩瓥鐣ユ暟鎹搴撶$悊锻戒护锻戒护add銆乨elete銆乻how(鎴栬卨ist)娉ㄦ剰锛氱瓥鐣ヨ矾鐢(policy routing)涓岖瓑浜庤矾鐢辩瓥鐣(rouing policy)銆傚湪镆愪簺𨱍呭喌涓嬶纴鎴戜滑涓嶅彧鏄闇瑕侀氲繃鏁版嵁鍖呯殑鐩镄勫湴鍧鍐冲畾璺鐢憋纴鍙鑳借缮闇瑕侀氲繃鍏朵粬涓浜涘烟锛氭簮鍦板潃銆両P鍗忚銆佷紶杈揿眰绔鍙g敋镊虫暟鎹鍖呯殑璐熻浇銆傝繖灏卞彨锅氾细绛栫暐璺鐢(policy routing)銆
8.5. ip rule add 钬 鎻掑叆鏂扮殑瑙勫垯ip rule delete 钬 鍒犻櫎瑙勫垯缂╁啓锛歛dd銆乤锛沝elete銆乨el銆乨
绀轰緥1: 阃氲繃璺鐢辫〃inr.ruhep璺鐢辨潵镊婧愬湴鍧涓192.203.80/24镄勬暟鎹鍖卛p ru add from 192.203.80/24 table inr.ruhep prio 220
绀轰緥2:鎶婃簮鍦板潃涓193.233.7.83镄勬暟鎹鎶ョ殑婧愬湴鍧杞鎹涓192.203.80.144锛屽苟阃氲繃琛1杩涜岃矾鐢眎p ru add from 193.233.7.83 nat 192.203.80.144 table 1 prio 320
绀轰緥3:鍒犻櫎镞犵敤镄勭己鐪佽勫垯ip ru del prio 32767
8.7. ip rule show 钬 鍒楀嚭璺鐢辫勫垯缂╁啓锛歴how銆乴ist銆乻h銆乴s銆乴绀轰緥1:# ip ru ls0:from all lookup local32762:from 192.168.4.89 lookup fddi15332764:from 192.168.4.88 lookup fddi15332766:from all lookup main32767:from all lookup 253钬斺斺斺斺斺斺斺斺9.ip maddress 钬 澶氭挱鍦板潃绠$悊缂╁啓锛歴how銆乴ist銆乻h銆乴s銆乴9.3.ip maddress show 钬 鍒楀嚭澶氭挱鍦板潃绀轰緥1: # ip maddr ls mmy
9.4. ip maddress add 钬 锷犲叆澶氭挱鍦板潃ip maddress delete 钬 鍒犻櫎澶氭挱鍦板潃缂╁啓锛歛dd銆乤锛沝elete銆乨el銆乨浣跨敤杩欎袱涓锻戒护锛屾垜浠鍙浠ユ坊锷狅纺鍒犻櫎鍦ㄧ绣缁沧帴鍙d笂鐩戝惉镄勯摼璺灞傚氭挱鍦板潃銆傝繖涓锻戒护鍙鑳界$悊阈捐矾灞傚湴鍧銆
绀轰緥1: 澧炲姞# ip maddr add 33:33:00:00:00:01 dev mmy绀轰緥2: 镆ョ湅# ip -O maddr ls mmy2:mmylink33:33:00:00:00:01 users 2 staticlink01:00:5e:00:00:01绀轰緥3: 鍒犻櫎# ip maddr del 33:33:00:00:00:01 dev mmy钬斺斺斺斺斺斺斺斺10.ip mroute 钬 澶氭挱璺鐢辩紦瀛樼$悊
10.4.ip mroute show 钬 鍒楀嚭澶氭挱璺鐢辩紦瀛樻浔鐩缂╁啓锛歴how銆乴ist銆乻h銆乴s銆乴
绀轰緥1:镆ョ湅# ip mroute ls(193.232.127.6, 224.0.1.39)Iif: unresolved(193.232.244.34, 224.0.1.40)Iif: unresolved(193.233.7.65, 224.66.66.66)Iif: eth0Oifs: pimreg绀轰緥2:镆ョ湅# ip -s mr ls 224.66/16(193.233.7.65, 224.66.66.66)Iif: eth0Oifs: pimreg9383 packets, 300256 bytes钬斺斺斺斺斺斺斺斺11. ip tunnel 钬 阃氶亾閰岖疆缂╁啓tunnel銆乼unl
11.4.ip tunnel add 钬 娣诲姞鏂扮殑阃氶亾ip tunnel change 钬 淇鏀圭幇链夌殑阃氶亾ip tunnel delete 钬 鍒犻櫎涓涓阃氶亾缂╁啓锛歛dd銆乤锛沜hange銆乧hg锛沝elete銆乨el銆乨绀轰緥1:寤虹珛涓涓镣瑰圭偣阃氶亾锛屾渶澶TTL鏄32# ip tunnel add Cisco mode sit remote 192.31.7.104 local 192.203.80.1 ttl 32
11.4.ip tunnel show 钬 鍒楀嚭鐜版湁镄勯氶亾缂╁啓锛歴how銆乴ist銆乻h銆乴s銆乴绀轰緥1:# ip -s tunl ls Cisco钬斺斺斺斺斺斺斺斺12. ip monitor鍜宺tmon 钬 鐘舵佺洃瑙唅p锻戒护鍙浠ョ敤浜庤繛缁鍦扮洃瑙呜惧囥佸湴鍧鍜岃矾鐢辩殑鐘舵併傝繖涓锻戒护阃夐”镄勬牸寮忔湁镣逛笉钖岋纴锻戒护阃夐”镄勫悕瀛楀彨锅歮onitor锛屾帴镌鏄镎崭綔瀵硅薄锛歩p monitor [ file FILE ] [ all | OBJECT-LIST ]绀轰緥1:# rtmon file /var/log/rtmon.log绀轰緥2:# ip monitor file /var/log/rtmon.log r
C. Linux里面查看本机路由表命令是什么
通过netstat命令
netstat命令一直是Linux中打印路由表信息一种广泛使用的方法。然而,它被ip route命令正式取代。无论如何,我们都需要它,因为它仍然是检索所需信息的一种方法。
以下是使用此命令的方法:
$ netstat -rn
如何在Ubuntu中查看网络路由表
-r此标志用于显示内核路由表
如何在Ubuntu中查看网络路由表
-n此标志用于显示数字地址
如何在Ubuntu中查看网络路由表
D. linux如何查看路由表
使用 route 命令可以查看 Linux 内核路由表。
Route命令是用于操作基于内核ip路由表,它的主要作用是创建一个静态路由让指定一个主机或者一个网络通过一个网络接口,如eth0。当使用"add"或者"del"参数时,路由表被修改,如果没有参数,则显示路由表当前的内容。
设置内核路由表的命令格式是:
# route [add|del] [-net|-host] target [netmask Nm] [gw Gw] [[dev] If]
(4)linux查看路由表命令扩展阅读
route命令参数介绍:
-c显示更多信息
-n不解析名字
-v显示详细的处理信息
-F显示发送信息
-C显示路由缓存
-f清除所有网关入口的路由表。
-p与add命令一起使用时使路由具有永久性。