溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Linux CentOS 7網(wǎng)絡配置基礎

發(fā)布時間:2020-06-11 09:05:04 來源:網(wǎng)絡 閱讀:1507 作者:wx5d2c2d660c282 欄目:系統(tǒng)運維

查看主機名稱

hostname命令:查看或設置當前主機名

Linux CentOS 7網(wǎng)絡配置基礎

修改主機名稱

hostnamectl set-hostname 新主機名稱 命令:修改當前主機名稱

Linux CentOS 7網(wǎng)絡配置基礎

在配置文件“/etc/sysconfig/network”中直接修改
Linux CentOS 7網(wǎng)絡配置基礎

查看網(wǎng)絡接口信息

ifconfig [網(wǎng)絡接口名]命令:查看指定網(wǎng)絡接口的信息,不指定接口則顯示所有接口信息。

Linux CentOS 7網(wǎng)絡配置基礎

下面解釋一下幾個重要的參數(shù):

inet 192.168.52.131                                                      //IP地址
netmask 255.255.255.0                                               //子網(wǎng)掩碼
broadcast 192.168.52.255                                          //廣播地址
inet6 fe80::8629:c3e2:139c:884a                              //ipv6地址
ether 00:0c:29:7a:41:33                                              //MAC地址

設置網(wǎng)絡參數(shù)的方式:

臨時配置:ifconfig 網(wǎng)絡接口名稱 IP地址 命令----------使用命令調(diào)整網(wǎng)絡參數(shù)
可以快速直接的修改網(wǎng)絡參數(shù),一般適合在調(diào)試網(wǎng)絡過程中使用,系統(tǒng)重啟后所做的修改都會消失。
Linux CentOS 7網(wǎng)絡配置基礎
Linux CentOS 7網(wǎng)絡配置基礎
固定設置:通過修改配置文件來修改網(wǎng)絡參數(shù),適合對服務器設置固定參數(shù)時使用,需要重啟網(wǎng)絡服務或重啟系統(tǒng)以后才會生效。
Linux CentOS 7網(wǎng)絡配置基礎

網(wǎng)卡的禁用和激活

禁用網(wǎng)卡:ifconfig 網(wǎng)絡接口 down

[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.52.131  netmask 255.255.255.0  broadcast 192.168.52.255
        inet6 fe80::8629:c3e2:139c:884a  prefixlen 64  scopeid 0x20<link>
          ..................................                                                                                                      //省略部分內(nèi)容
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>
          ..................................                                                                                                      //省略部分內(nèi)容
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:31:df:fc  txqueuelen 1000  (Ethernet)
          ..................................                                                                                                      //省略部分內(nèi)容
[root@localhost ~]# ifconfig ens33 down
[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>
          ..................................                                                                                                      //省略部分內(nèi)容
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:31:df:fc  txqueuelen 1000  (Ethernet)
          ..................................                                                                                                      //省略部分內(nèi)容

啟用網(wǎng)卡:ifconfig 網(wǎng)絡接口 up

[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>
          ..................................                                                                                                      //省略部分內(nèi)容
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:31:df:fc  txqueuelen 1000  (Ethernet)
          ..................................                                                                                                      //省略部分內(nèi)容
[root@localhost ~]# ifconfig ens33 up
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.52.131  netmask 255.255.255.0  broadcast 192.168.52.255
        inet6 fe80::8629:c3e2:139c:884a  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:7a:41:33  txqueuelen 1000  (Ethernet)
          ..................................                                                                                                      //省略部分內(nèi)容
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>
          ..................................                                                                                                      //省略部分內(nèi)容
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:31:df:fc  txqueuelen 1000  (Ethernet)

啟用網(wǎng)絡接口還可以用命令“ifup 網(wǎng)絡接口 ”,關閉網(wǎng)絡接口還可以用命令“ifdown 網(wǎng)絡接口”。重啟網(wǎng)絡服務一般用命令“service network restart”或“systemctl restart network”。

設置虛擬網(wǎng)絡接口:

ifconfig 網(wǎng)絡接口:序號 IP地址 注意:虛擬網(wǎng)絡接口關閉了就直接刪除了,不能再重新開啟。

[root@localhost ~]# ifconfig 
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.52.131  netmask 255.255.255.0  broadcast 192.168.52.255
        inet6 fe80::8629:c3e2:139c:884a  prefixlen 64  scopeid 0x20<link>
          ..................................                                                                                                      //省略部分內(nèi)容
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>
          ..................................                                                                                                      //省略部分內(nèi)容
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:31:df:fc  txqueuelen 1000  (Ethernet)
          ..................................                                                                                                      //省略部分內(nèi)容
[root@localhost ~]# ifconfig ens33:0 192.168.100.100
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.52.131  netmask 255.255.255.0  broadcast 192.168.52.255
        inet6 fe80::8629:c3e2:139c:884a  prefixlen 64  scopeid 0x20<link>
          ..................................                                                                                                      //省略部分內(nèi)容
ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.100  netmask 255.255.255.0  broadcast 192.168.100.255
        ether 00:0c:29:7a:41:33  txqueuelen 1000  (Ethernet)
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>
          ..................................                                                                                                      //省略部分內(nèi)容
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:31:df:fc  txqueuelen 1000  (Ethernet)
          ..................................                                                                                                      //省略部分內(nèi)容

查看網(wǎng)絡連接情況

netstat命令:查看系統(tǒng)的網(wǎng)絡連接狀態(tài)、路由表、接口統(tǒng)計等信息

常用選項:

-a:                    列出所有當前的連接
-n:                    禁用域名解析功能
-p:                    查看進程信息
-t:                     列出 TCP 協(xié)議的連接
-u:                   列出 UDP 協(xié)議的連接
-r:                     打印內(nèi)核路由信息

Linux CentOS 7網(wǎng)絡配置基礎

查看路由表條目

route命令:查看或設置主機中路由表信息,跟“netstat -r”類似

Linux CentOS 7網(wǎng)絡配置基礎

在Linux6版本中“0.0.0.0”會以“*”的形式顯示出來,只有加上“-n”選項才能以“0.0.0.0”顯示出來。

設置路由記錄

添加到指定網(wǎng)段的路由記錄:
route add -net 網(wǎng)段地址 gw IP地址
Linux CentOS 7網(wǎng)絡配置基礎
刪除到指定網(wǎng)段的路由記錄:
route del -net 網(wǎng)段地址
Linux CentOS 7網(wǎng)絡配置基礎
向路由表中添加默認網(wǎng)關記錄:
route add default gw IP地址
Linux CentOS 7網(wǎng)絡配置基礎
刪除路由表中的默認網(wǎng)關記錄:
route del default gw IP地址
Linux CentOS 7網(wǎng)絡配置基礎

測試網(wǎng)絡連接

ping命令:測試網(wǎng)絡連通性,按[Ctrl+C]終止測試

Linux CentOS 7網(wǎng)絡配置基礎

跟蹤數(shù)據(jù)包

traceroute 目標主機地址 命令:測試從當前主機到目的主機之間經(jīng)過的網(wǎng)絡節(jié)點

當我們的網(wǎng)絡不能夠正常通訊的時候,可以用traceroute命令,看一下是那個節(jié)點出了問題。
Linux CentOS 7網(wǎng)絡配置基礎

域名解析

nslookup 目標主機地址 [DNS服務器地址] 命令:測試DNS域名解析

Linux CentOS 7網(wǎng)絡配置基礎

DNS地址更改

在配置文件“/etc/resolv.conf”里直接修改即可
Linux CentOS 7網(wǎng)絡配置基礎

本地主機映射文件

“/etc/hosts”保存主機名與IP地址的映射記錄
默認情況下,系統(tǒng)首先從hosts文件查找解析記錄。找不到的情況下才會通過DNS服務器解析,hosts文件能夠加快訪問的速度,但是只對當前主機有效。
Linux CentOS 7網(wǎng)絡配置基礎

scp命令遠程復制

將本地文件同步到遠程服務器
scp 本地同步文件路徑 用戶@IP:遠程服務器文件路徑
我們在host01主機的“/etc/hosts”文件中添加兩個DNS映射記錄,然后在host01主機上通過scp命令,將它同步到host02主機上。
Linux CentOS 7網(wǎng)絡配置基礎
Linux CentOS 7網(wǎng)絡配置基礎
Linux CentOS 7網(wǎng)絡配置基礎

將遠程服務器文件同步到本地
scp 用戶@IP:遠程服務器文件路徑 本地同步文件路徑
我們在host02主機的“/etc/hosts”文件中再添加兩個DNS映射記錄,然后在host01主機上將它從host02主機上同步過來。
Linux CentOS 7網(wǎng)絡配置基礎
Linux CentOS 7網(wǎng)絡配置基礎

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI