配置路由,追蹤路由
專注于為中小企業(yè)提供網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站制作服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)福山免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上千余家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
前言
查看網(wǎng)絡(luò)設(shè)置
測(cè)試網(wǎng)絡(luò)連接
使用網(wǎng)絡(luò)配置命令
[root@localhost ~]# ifconfig 網(wǎng)絡(luò)接口名
[root@localhost ~]# ifconfig ens33
'ens33第一塊以太網(wǎng)卡的名稱': flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
'inet IP地址 192.168.139.153' 'netmask 子網(wǎng)掩碼 255.255.255.0' 'broadcast 廣播地址 192.168.139.255'
inet6 fe80::413b:c9ad:e0e:1afc prefixlen 64 scopeid 0x20<link>
ether '00:0c:29:d6:c0:8a MAC地址' txqueuelen 1000 (Ethernet)
RX packets 28803 bytes 2100162 (2.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 21495 bytes 3147424 (3.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
網(wǎng)卡名稱ens33可以修改,修改時(shí)機(jī)是在安裝系統(tǒng)時(shí)修改網(wǎng)卡名稱
查看或設(shè)置當(dāng)前主機(jī)名
[root@localhost ~]# hostname
[root@localhost ~]# hostname
localhost主機(jī)名.'localdomain含義是域,后期會(huì)提到'
[root@localhost ~]# hostnamectl --help
hostnamectl [OPTIONS...] COMMAND ...
Query or change system hostname.
-h --help Show this help
--version Show package version
--no-ask-password Do not prompt for password
-H --host=[USER@]HOST Operate on remote host
-M --machine=CONTAINER Operate on local container
--transient Only set transient hostname
--static Only set static hostname
--pretty Only set pretty hostname
Commands:
status Show current hostname settings
set-hostname NAME Set system hostname
set-icon-name NAME Set icon name for host
set-chassis NAME Set chassis type for host
set-deployment NAME Set deployment environment for host
set-location NAME Set location for host
[root@localhost ~]# hostnamectl set-hostname gsy
[root@localhost ~]# su
[root@gsy ~]#
設(shè)置主機(jī)名的第二種方法,即修改配置文件
/etc/hostname 配置文件
[root@gsy ~]# hostname
gsy
[root@gsy ~]# vim /etc/sysconfig/network
'這個(gè)配置文件的修改適用于centos 6,不適用于centos 7'
# Created by anaconda
HOST=MySQL
~
[root@965 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.139.2 0.0.0.0 UG 100 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
192.168.139.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
[root@965 ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default gateway 0.0.0.0 UG 100 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
192.168.139.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
Destination 網(wǎng)段 Gateway 網(wǎng)關(guān) Genmask 子網(wǎng)掩碼 metric 度量值
在centos 7中,route 與route -n 的區(qū)別在于默認(rèn)網(wǎng)絡(luò)改為數(shù)字0.0.0.0
在centos 6中,route 與route -n 具體區(qū)別如下顯示
[root@gsy ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.139.0 * 255.255.255.0 U 1 0 0 eth0
default 192.168.139.2 0.0.0.0 UG 0 0 0 eth0
[root@gsy ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.139.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
0.0.0.0 192.168.139.2 0.0.0.0 UG 0 0 0 eth0
選項(xiàng) | 解釋 |
---|---|
-a | 顯示所有 |
-n | 顯示序列號(hào) |
-p | 顯示端口協(xié)議 |
-t | 顯示TCP協(xié)議 |
-u | 顯示UDP協(xié)議 |
-r | 顯示route |
描述 DESCRIPTION
Netstat 程序顯示Linux網(wǎng)絡(luò)子系統(tǒng)的信息。 輸出信息的類型是由第一個(gè)參數(shù)控制的,就像這樣:
(none)
無(wú)選項(xiàng)時(shí), netstat 顯示打開(kāi)的套接字.
如果不指定任何地址族,那么打印出所有已配置地址族的有效套接字。
--route , -r
顯示內(nèi)核路由表。
--groups , -g
顯示IPv4 和 IPv6的IGMP組播組成員關(guān)系信息。
--interface=iface , -i
顯示所有網(wǎng)絡(luò)接口列表或者是指定的 iface 。
--masquerade , -M
顯示一份所有經(jīng)偽裝的會(huì)話列表。
--statistics , -s
顯示每種協(xié)議的統(tǒng)計(jì)信息。
選項(xiàng) OPTIONS
--verbose , -v
詳細(xì)模式運(yùn)行。特別是打印一些關(guān)于未配置地址族的有用信息。
--numeric , -n
顯示數(shù)字形式地址而不是去解析主機(jī)、端口或用戶名。
--numeric-hosts
顯示數(shù)字形式的主機(jī)但是不影響端口或用戶名的解析。
--numeric-ports
顯示數(shù)字端口號(hào),但是不影響主機(jī)或用戶名的解析。
--numeric-users
顯示數(shù)字的用戶ID,但是不影響主機(jī)和端口名的解析。
--protocol=family , -A
指定要顯示哪些連接的地址族(也許在底層協(xié)議中可以更好地描述)。 family
以逗號(hào)分隔的地址族列表,比如 inet, unix, ipx, ax25, netrom, 和 ddp。 這樣和使用 --inet, --unix
(-x), --ipx, --ax25, --netrom, 和 --ddp 選項(xiàng)效果相同。
地址族 inet 包括raw, udp 和tcp 協(xié)議套接字。
-c, --continuous
將使 netstat 不斷地每秒輸出所選的信息。
-e, --extend
顯示附加信息。使用這個(gè)選項(xiàng)兩次來(lái)獲得所有細(xì)節(jié)。
-o, --timers
包含與網(wǎng)絡(luò)定時(shí)器有關(guān)的信息。
-p, --program
顯示套接字所屬進(jìn)程的PID和名稱。
-l, --listening
只顯示正在偵聽(tīng)的套接字(這是默認(rèn)的選項(xiàng))
-a, --all
顯示所有正在或不在偵聽(tīng)的套接字。加上 --interfaces 選項(xiàng)將顯示沒(méi)有標(biāo)記的接口。
-F
顯示FIB中的路由信息。(這是默認(rèn)的選項(xiàng))
-C
顯示路由緩沖中的路由信息。
delay
netstat將循環(huán)輸出統(tǒng)計(jì)信息,每隔 delay 秒。
[root@965 ~]# netstat -natp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1296/DNSmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1116/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1117/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1300/master
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 13953/sshd: root@pt
tcp 0 36 192.168.139.153:22 192.168.139.1:64738 ESTABLISHED 13953/sshd: root@pt
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::22 :::* LISTEN 1116/sshd
tcp6 0 0 ::1:631 :::* LISTEN 1117/cupsd
tcp6 0 0 ::1:25 :::* LISTEN 1300/master
tcp6 0 0 ::1:6010 :::* LISTEN 13953/sshd: root@pt
sshd 指遠(yuǎn)程訪問(wèn)
可以結(jié)合檢索命令去針對(duì)性查看
[root@965 ~]# netstat -natp | grep "22"
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1296/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1116/sshd
tcp 0 36 192.168.139.153:22 192.168.139.1:64738 ESTABLISHED 13953/sshd: root@pt
tcp6 0 0 :::22 :::* LISTEN 1116/sshd
[root@965 ~]# netstat -natp | grep ssh
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1116/sshd
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 13953/sshd: root@pt
tcp 0 36 192.168.139.153:22 192.168.139.1:64738 ESTABLISHED 13953/sshd: root@pt
tcp6 0 0 :::22 :::* LISTEN 1116/sshd
tcp6 0 0 ::1:6010 :::* LISTEN 13953/sshd: root@pt
[root@965 ~]# netstat -naup
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp 0 0 192.168.139.153:40345 192.168.139.2:53 ESTABLISHED 129301/hostname
udp 0 0 0.0.0.0:11836 0.0.0.0:* 7860/dhclient
udp 0 0 0.0.0.0:44612 0.0.0.0:* 707/avahi-daemon: r
udp 832 0 192.168.139.153:56951 192.168.139.2:53 ESTABLISHED 124308/ssh
udp 0 0 192.168.122.1:53 0.0.0.0:* 1296/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 1296/dnsmasq
udp 0 0 0.0.0.0:68 0.0.0.0:* 7860/dhclient
udp 0 0 0.0.0.0:5353 0.0.0.0:* 707/avahi-daemon: r
udp 0 0 127.0.0.1:323 0.0.0.0:* 732/chronyd
udp6 0 0 ::1:323 :::* 732/chronyd
udp6 0 0 :::49510 :::* 7860/dhclient
[root@965 ~]# netstat -naup | grep 22
udp 0 0 192.168.122.1:53 0.0.0.0:* 1296/dnsmasq
[root@965 ~]# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.139.2 0.0.0.0 UG 0 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
192.168.139.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33
[root@965 ~]# netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default gateway 0.0.0.0 UG 0 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
192.168.139.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33
linux中網(wǎng)卡配置
[root@965 network-scripts]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="0f432513-5d7a-455c-88b4-257a9a1dbb45"
DEVICE="ens33"
ONBOOT="yes"
修改為
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static" '將原來(lái)的dhcp自動(dòng)分配ip地址協(xié)議改為靜態(tài)協(xié)議'
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="0f432513-5d7a-455c-88b4-257a9a1dbb45"
DEVICE="ens33"
ONBOOT="yes"
IPADDR=192.168.10.10 'ip地址為192.168.10.10'
NETMASK=255.255.255.0 '子網(wǎng)掩碼為255.255.255.0'
GATEWAY=192.168.10.1 '網(wǎng)關(guān)為192.168.10.1'
:wq
配置完畢后重啟網(wǎng)絡(luò)服務(wù)
[root@965 network-scripts]# systemctl restart network
[root@965 network-scripts]# service network restart
Restarting network (via systemctl): [ 確定 ]
[root@965 network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.10 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::413b:c9ad:e0e:1afc prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:d6:c0:8a txqueuelen 1000 (Ethernet)
RX packets 121888 bytes 9724226 (9.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 161138 bytes 29666777 (28.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
host1 配置完畢,接下來(lái)配置host2
然后配置R1和R2
R1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#int f0/0
R1(config-if)#ip add 192.168.10.1 255.255.255.0
R1(config-if)#no shut
*Mar 1 00:12:04.515: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
*Mar 1 00:12:05.515: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R1(config-if)#int f0/1
R1(config-if)#ip add 192.168.20.1 255.255.255.0
R1(config-if)#no shut
*Mar 1 00:12:19.323: %LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to up
*Mar 1 00:12:20.323: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
R1(config-if)#ip route 0.0.0.0 0.0.0.0 192.168.20.20
R2#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#int f0/0
R2(config-if)#ip add 192.168.20.20 255.255.255.0
R2(config-if)#no shut
R2(config-if)#int f0/1
*Mar 1 00:12:46.323: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
*Mar 1 00:12:47.323: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R2(config-if)#ip add 192.168.30.1 255.255.255.0
R2(config-if)#no shut
R2(config-if)#ip route 0.0.0.0 0.0.0.0 192.168.20.1
[root@965 ~]# ping 192.168.30.30
PING 192.168.30.30 (192.168.30.30) 56(84) bytes of data.
64 bytes from 192.168.30.30: icmp_seq=3 ttl=126 time=47.3 ms
64 bytes from 192.168.30.30: icmp_seq=4 ttl=126 time=43.7 ms
64 bytes from 192.168.30.30: icmp_seq=5 ttl=126 time=43.4 ms
64 bytes from 192.168.30.30: icmp_seq=6 ttl=126 time=42.4 ms
^C
--- 192.168.30.30 ping statistics ---
6 packets transmitted, 4 received, 33% packet loss, time 5013ms
rtt min/avg/max/mdev = 42.432/44.244/47.386/1.881 ms
[root@965483 ~]# traceroute 192.168.30.30
traceroute to 192.168.30.30 (192.168.30.30), 30 hops max, 60 byte packets
1 gateway (192.168.10.1) 3.021 ms 12.829 ms 23.697 ms
2 192.168.20.20 (192.168.20.20) 33.630 ms 43.493 ms 54.322 ms
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 * * *
啟用server中的相關(guān)配置,可以實(shí)現(xiàn)遠(yuǎn)程終端鏈接
中間IP地址自動(dòng)改變,要及時(shí)調(diào)整
[root@localhost ~]# nslookup www.google.com
Server: 192.168.139.2 'dns服務(wù)器地址'
Address: 192.168.139.2#53
Non-authoritative answer: '反饋的解析結(jié)果'
Name: www.google.com
Address: 74.86.226.234
windows中的檢測(cè)
C:\Users\GSY>nslookup www.google.com
服務(wù)器: ns.gwbnnj.net.cn 'DNS服務(wù)器地址'
Address: 211.162.31.80
非權(quán)威應(yīng)答:
名稱: www.google.com
Addresses: 2404:6800:4012::2004 'ipv6的地址'
74.86.226.234 '反饋的結(jié)果'
C:\Users\GSY>nslookup www.taobao.com
服務(wù)器: ns.gwbnnj.net.cn
Address: 211.162.31.80
非權(quán)威應(yīng)答:
名稱: www.taobao.com.danuoyi.tbcache.com 'taobao實(shí)際的域名'
Addresses: 2409:8c28:2808:5:3::3fa
2409:8c28:801:3:3::3fa
2409:8c28:2808:5:3::3f9
2409:8c28:801:3:3::3f9
111.3.79.235
111.3.79.234
211.138.124.237
Aliases: www.taobao.com '別名'
服務(wù)器指的是DNS解析服務(wù)器,后面nj是南京的意思
可以把解析后的地址復(fù)制到瀏覽器中去訪問(wèn),百度的可以,但是淘寶的不行,這是因?yàn)樽隽税踩雷o(hù),dns服務(wù)器也做了相應(yīng)的防護(hù)
設(shè)置網(wǎng)絡(luò)接口的IP地址、子網(wǎng)掩碼
ifconfig 接口名(網(wǎng)卡名) ip地址 [netmask 子網(wǎng)掩碼]
ifconfig 網(wǎng)絡(luò)接口 ip地址[/掩碼長(zhǎng)度]
禁用或重新激活網(wǎng)卡
ifconfig 網(wǎng)絡(luò)接口 up
ifconfig 網(wǎng)絡(luò)接口 down
設(shè)置虛擬網(wǎng)絡(luò)接口
ifconfig 接口名:序號(hào) IP地址
接口名 ens33
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.139.157'ip地址' netmask 255.255.255.0 '子網(wǎng)掩碼' broadcast 192.168.139.255 '廣播地址'
inet6 fe80::413b:c9ad:e0e:1afc prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:d6:c0:8a txqueuelen 1000 (Ethernet)
RX packets 4494 bytes 300077 (293.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 144 bytes 15965 (15.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
臨時(shí)修改,只用與維護(hù)時(shí)使用,
序號(hào),0-123456,相當(dāng)于邏輯接口,
當(dāng)一臺(tái)主機(jī)需要用多臺(tái)IP地址時(shí),可以使用邏輯接口配置
[root@localhost ~]# ifconfig ens33 8.8.8.8
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
'inet 8.8.8.8 netmask 255.0.0.0 broadcast 8.255.255.255'
inet6 fe80::413b:c9ad:e0e:1afc prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:d6:c0:8a txqueuelen 1000 (Ethernet)
RX packets 4544 bytes 305199 (298.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 162 bytes 19317 (18.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# ifconfig ens33 8.8.8.8/24
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
'inet 8.8.8.8 netmask 255.255.255.0 broadcast 8.8.8.255'
inet6 fe80::413b:c9ad:e0e:1afc prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:d6:c0:8a txqueuelen 1000 (Ethernet)
RX packets 4568 bytes 308317 (301.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 170 bytes 21475 (20.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# ifconfig ens33:1 192.168.9.9
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 8.8.8.8 netmask 255.255.255.0 broadcast 8.8.8.255
inet6 fe80::413b:c9ad:e0e:1afc prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:d6:c0:8a txqueuelen 1000 (Ethernet)
RX packets 4663 bytes 315910 (308.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 197 bytes 25003 (24.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.9.9 netmask 255.255.255.0 broadcast 192.168.9.255
ether 00:0c:29:d6:c0:8a txqueuelen 1000 (Ethernet)
[root@localhost ~]# ifconfig ens33:1 down ‘關(guān)掉ens33:1’
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 8.8.8.8 netmask 255.255.255.0 broadcast 8.8.8.255
inet6 fe80::413b:c9ad:e0e:1afc prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:d6:c0:8a txqueuelen 1000 (Ethernet)
RX packets 4683 bytes 317292 (309.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 203 bytes 25510 (24.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# ifconfig ens33:1 up '再次開(kāi)啟會(huì)發(fā)現(xiàn)無(wú)法找到這個(gè)地址'
SIOCSIFFLAGS: 無(wú)法指定被請(qǐng)求的地址
[root@localhost ~]# ifconfig ens33 down '關(guān)掉物理網(wǎng)卡ens33'
[root@localhost ~]# ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 1672 bytes 144872 (141.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1672 bytes 144872 (141.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:e1:7d:d2 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# ifconfig ens33 up '可以成功開(kāi)啟'
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.139.157 netmask 255.255.255.0 broadcast 192.168.139.255
inet6 fe80::413b:c9ad:e0e:1afc prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:d6:c0:8a txqueuelen 1000 (Ethernet)
RX packets 4739 bytes 322970 (315.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 229 bytes 29270 (28.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
邏輯子接口(例:ens33:1)的down相當(dāng)于把IP地址釋放掉了
gw 下一跳地址
-net 目標(biāo)網(wǎng)段
Destination Gateway Genmask Flags Metric Ref Use Iface
'0.0.0.0 192.168.139.2 0.0.0.0 UG 100 0 0 ens33
默認(rèn)網(wǎng)關(guān),即可以變相理解為默認(rèn)路由
[root@localhost ~]# route add -net 192.168.10.0 gw 192.168.139.157
SIOCADDRT: 無(wú)效的參數(shù)
[root@localhost ~]# route add -net 192.168.10.0/24 gw 192.168.139.157
[root@localhost ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default gateway 0.0.0.0 UG 100 0 0 ens33
'192.168.10.0 localhost.local 255.255.255.0 UG 0 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
192.168.139.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.139.2 0.0.0.0 UG 100 0 0 ens33
192.168.10.0 192.168.139.157 255.255.255.0 UG 0 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
192.168.139.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
[root@localhost ~]# route add -net 192.168.100.0/24 gw 192.168.139.157
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway '下一跳' Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.139.2 0.0.0.0 UG 100 0 0 ens33
192.168.10.0 192.168.139.157 255.255.255.0 UG 0 0 0 ens33
'192.168.100.0 192.168.139.157 255.255.255.0 UG 0 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
192.168.139.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
[root@localhost ~]# route del -net 192.168.100.0/24 gw 192.168.139.157
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.139.2 0.0.0.0 UG 100 0 0 ens33
192.168.10.0 192.168.139.157 255.255.255.0 UG 0 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
192.168.139.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
hostname 主機(jī)名稱
[root@localhost ~]# hostname gsy '第一種方法'
[root@localhost ~]# su
[root@gsy ~]# hostnamectl set-hostname hostname '第二種方法'
[root@gsy ~]# su '或者bash'
[root@hostname ~]#
第三種方法:vim /etc/hostname 修改主機(jī)名,然后保存,關(guān)機(jī)重啟即可
第四種方法:vim /etc/sysconfig/networkl 修改主機(jī)名,關(guān)機(jī)重啟(不適用于7,適用于6)
[root@dabendan ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet" '類型,以太網(wǎng)卡'
PROXY_METHOD="none" '代理方法'
BROWSER_ONLY="no" '瀏覽器'
BOOTPROTO="dhcp" '雇傭,ip地址獲取,dhcp獲取'
DEFROUTE="yes" '默認(rèn)路由'
IPV4_FAILURE_FATAL="no" 'ipv4失敗驗(yàn)證 否'
IPV6INIT="yes" 'ipv6 初始化 開(kāi)啟'
IPV6_AUTOCONF="yes" 'ipv6自動(dòng)配置 開(kāi)啟'
IPV6_DEFROUTE="yes" 'ipv6 默認(rèn)配置 開(kāi)啟'
IPV6_FAILURE_FATAL="no" 'ipv6失敗驗(yàn)證 否'
IPV6_ADDR_GEN_MODE="stable-privacy" 'ipv6地址協(xié)議模式v6為穩(wěn)定私有'
NAME="ens33" '名稱'
UUID="0f432513-5d7a-455c-88b4-257a9a1dbb45"
DEVICE="ens33" '設(shè)備'
ONBOOT="yes" '在boot內(nèi)核啟動(dòng)時(shí)網(wǎng)卡開(kāi)啟'
可以修改為靜態(tài)IP地址網(wǎng)卡
BOOTPROTO="static" '靜態(tài)獲取'
IPADDR=指定ip地址
NETMASK=指定子網(wǎng)掩碼
GAREWAY=指定網(wǎng)關(guān)
[root@localhost ~]# systemctl restart network
[root@localhost ~]# ifdown ens33
[root@localhost ~]# ifup ens33
1.添加網(wǎng)卡,然后自動(dòng)識(shí)別(不需要重啟)
禁用啟用網(wǎng)絡(luò)接口也可以在配置文件中修改,就是把ONBOOT=no
vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=chenggong
:wq
reboot '重啟生效'
這個(gè)第四種方法不能用于centos 7 ,在centos 6 中可以使用
[root@dabendan ~]# vim /etc/resolv.conf
# Generated by NetworkManager
search localdomain'主機(jī)域'
nameserver 192.168.139.2 '默認(rèn)網(wǎng)關(guān),也可以手動(dòng)配置'
[root@dabendan ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
119.75.218.70 www.baidu.com
域名解析會(huì)優(yōu)先去查看/etc/hosts 映射文件,若是沒(méi)有,就會(huì)再去找dns服務(wù)器
windows中hosts的文件所在位置
查看網(wǎng)絡(luò)配置
測(cè)試網(wǎng)絡(luò)連接
設(shè)置網(wǎng)絡(luò)地址參數(shù)
相關(guān)的配置文件
/etc/sysconfig/network主機(jī)名配置文件
/etc/resolv.conf 域名解析配置文件
本文名稱:理論:linux網(wǎng)絡(luò)服務(wù)-linux網(wǎng)絡(luò)設(shè)置
網(wǎng)頁(yè)鏈接:http://aaarwkj.com/article18/igspdp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、服務(wù)器托管、外貿(mào)建站、域名注冊(cè)、、做網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)