配置路由,追蹤路由mysql
前言linux
查看網絡設置sql
測試網絡鏈接shell
使用網絡配置命令vim
[root@localhost ~]# ifconfig 網絡接口名
[root@localhost ~]# ifconfig ens33 'ens33第一塊以太網卡的名稱': flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 'inet IP地址 192.168.139.153' '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 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
網卡名稱ens33能夠修改,修改時機是在安裝系統時修改網卡名稱windows
查看或設置當前主機名centos
[root@localhost ~]# hostname
[root@localhost ~]# hostname localhost主機名.'localdomain含義是域,後期會提到'
[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 ~]#
設置主機名的第二種方法,即修改配置文件瀏覽器
/etc/hostname 配置文件安全
[root@gsy ~]# hostname gsy [root@gsy ~]# vim /etc/sysconfig/network '這個配置文件的修改適用於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 網段 Gateway 網關 Genmask 子網掩碼 metric 度量值bash
在centos 7中,route 與route -n 的區別在於默認網絡改成數字0.0.0.0
在centos 6中,route 與route -n 具體區別以下顯示
[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
選項 | 解釋 |
---|---|
-a | 顯示全部 |
-n | 顯示序列號 |
-p | 顯示端口協議 |
-t | 顯示TCP協議 |
-u | 顯示UDP協議 |
-r | 顯示route |
描述 DESCRIPTION Netstat 程序顯示Linux網絡子系統的信息。 輸出信息的類型是由第一個參數控制的,就像這樣: (none) 無選項時, netstat 顯示打開的套接字. 若是不指定任何地址族,那麼打印出全部已配置地址族的有效套接字。 --route , -r 顯示內核路由表。 --groups , -g 顯示IPv4 和 IPv6的IGMP組播組成員關係信息。 --interface=iface , -i 顯示全部網絡接口列表或者是指定的 iface 。 --masquerade , -M 顯示一份全部經假裝的會話列表。 --statistics , -s 顯示每種協議的統計信息。 選項 OPTIONS --verbose , -v 詳細模式運行。特別是打印一些關於未配置地址族的有用信息。 --numeric , -n 顯示數字形式地址而不是去解析主機、端口或用戶名。 --numeric-hosts 顯示數字形式的主機可是不影響端口或用戶名的解析。 --numeric-ports 顯示數字端口號,可是不影響主機或用戶名的解析。 --numeric-users 顯示數字的用戶ID,可是不影響主機和端口名的解析。 --protocol=family , -A 指定要顯示哪些鏈接的地址族(也許在底層協議中能夠更好地描述)。 family 以逗號分隔的地址族列表,好比 inet, unix, ipx, ax25, netrom, 和 ddp。 這樣和使用 --inet, --unix (-x), --ipx, --ax25, --netrom, 和 --ddp 選項效果相同。 地址族 inet 包括raw, udp 和tcp 協議套接字。 -c, --continuous 將使 netstat 不斷地每秒輸出所選的信息。 -e, --extend 顯示附加信息。使用這個選項兩次來得到全部細節。 -o, --timers 包含與網絡定時器有關的信息。 -p, --program 顯示套接字所屬進程的PID和名稱。 -l, --listening 只顯示正在偵聽的套接字(這是默認的選項) -a, --all 顯示全部正在或不在偵聽的套接字。加上 --interfaces 選項將顯示沒有標記的接口。 -F 顯示FIB中的路由信息。(這是默認的選項) -C 顯示路由緩衝中的路由信息。 delay netstat將循環輸出統計信息,每隔 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 指遠程訪問
能夠結合檢索命令去針對性查看
[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中網卡配置
[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" '將原來的dhcp自動分配ip地址協議改成靜態協議' 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 '子網掩碼爲255.255.255.0' GATEWAY=192.168.10.1 '網關爲192.168.10.1' :wq
配置完畢後重啓網絡服務
[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 配置完畢,接下來配置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中的相關配置,能夠實現遠程終端連接
中間IP地址自動改變,要及時調整
[root@localhost ~]# nslookup www.google.com Server: 192.168.139.2 'dns服務器地址' Address: 192.168.139.2#53 Non-authoritative answer: '反饋的解析結果' Name: www.google.com Address: 74.86.226.234
windows中的檢測
C:\Users\GSY>nslookup www.google.com 服務器: ns.gwbnnj.net.cn 'DNS服務器地址' Address: 211.162.31.80 非權威應答: 名稱: www.google.com Addresses: 2404:6800:4012::2004 'ipv6的地址' 74.86.226.234 '反饋的結果' C:\Users\GSY>nslookup www.taobao.com 服務器: ns.gwbnnj.net.cn Address: 211.162.31.80 非權威應答: 名稱: www.taobao.com.danuoyi.tbcache.com 'taobao實際的域名' 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 '別名'
服務器指的是DNS解析服務器,後面nj是南京的意思
能夠把解析後的地址複製到瀏覽器中去訪問,百度的能夠,可是淘寶的不行,這是由於作了安全防禦,dns服務器也作了相應的防禦
設置網絡接口的IP地址、子網掩碼
ifconfig 接口名(網卡名) ip地址 [netmask 子網掩碼]
ifconfig 網絡接口 ip地址[/掩碼長度]
禁用或從新激活網卡
ifconfig 網絡接口 up
ifconfig 網絡接口 down
設置虛擬網絡接口
ifconfig 接口名:序號 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 '子網掩碼' 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
臨時修改,只用與維護時使用,
序號,0-123456,至關於邏輯接口,
當一臺主機須要用多臺IP地址時,可使用邏輯接口配置
[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 ‘關掉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 '再次開啓會發現沒法找到這個地址' SIOCSIFFLAGS: 沒法指定被請求的地址 [root@localhost ~]# ifconfig ens33 down '關掉物理網卡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 '能夠成功開啓' [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至關於把IP地址釋放掉了
gw 下一跳地址
-net 目標網段
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 默認網關,便可以變相理解爲默認路由
[root@localhost ~]# route add -net 192.168.10.0 gw 192.168.139.157 SIOCADDRT: 無效的參數 [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 主機名稱
[root@localhost ~]# hostname gsy '第一種方法' [root@localhost ~]# su [root@gsy ~]# hostnamectl set-hostname hostname '第二種方法' [root@gsy ~]# su '或者bash' [root@hostname ~]#
第三種方法:vim /etc/hostname 修改主機名,而後保存,關機重啓便可
第四種方法:vim /etc/sysconfig/networkl 修改主機名,關機重啓(不適用於7,適用於6)
[root@dabendan ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE="Ethernet" '類型,以太網卡' PROXY_METHOD="none" '代理方法' BROWSER_ONLY="no" '瀏覽器' BOOTPROTO="dhcp" '僱傭,ip地址獲取,dhcp獲取' DEFROUTE="yes" '默認路由' IPV4_FAILURE_FATAL="no" 'ipv4失敗驗證 否' IPV6INIT="yes" 'ipv6 初始化 開啓' IPV6_AUTOCONF="yes" 'ipv6自動配置 開啓' IPV6_DEFROUTE="yes" 'ipv6 默認配置 開啓' IPV6_FAILURE_FATAL="no" 'ipv6失敗驗證 否' IPV6_ADDR_GEN_MODE="stable-privacy" 'ipv6地址協議模式v6爲穩定私有' NAME="ens33" '名稱' UUID="0f432513-5d7a-455c-88b4-257a9a1dbb45" DEVICE="ens33" '設備' ONBOOT="yes" '在boot內核啓動時網卡開啓' 能夠修改成靜態IP地址網卡 BOOTPROTO="static" '靜態獲取' IPADDR=指定ip地址 NETMASK=指定子網掩碼 GAREWAY=指定網關
[root@localhost ~]# systemctl restart network
[root@localhost ~]# ifdown ens33
[root@localhost ~]# ifup ens33
1.添加網卡,而後自動識別(不須要重啓)
禁用啓用網絡接口也能夠在配置文件中修改,就是把ONBOOT=no
vim /etc/sysconfig/network NETWORKING=yes HOSTNAME=chenggong :wq reboot '重啓生效'
這個第四種方法不能用於centos 7 ,在centos 6 中可使用
[root@dabendan ~]# vim /etc/resolv.conf # Generated by NetworkManager search localdomain'主機域' nameserver 192.168.139.2 '默認網關,也能夠手動配置'
[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
域名解析會優先去查看/etc/hosts 映射文件,如果沒有,就會再去找dns服務器
windows中hosts的文件所在位置
查看網絡配置
測試網絡鏈接
設置網絡地址參數
相關的配置文件
/etc/sysconfig/network主機名配置文件
/etc/resolv.conf 域名解析配置文件