溫馨提示×

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

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Linux基本網(wǎng)絡(luò)設(shè)置

發(fā)布時(shí)間:2020-07-01 15:54:22 來(lái)源:網(wǎng)絡(luò) 閱讀:364 作者:wx5d3fd1efe40e3 欄目:系統(tǒng)運(yùn)維

一、內(nèi)容要點(diǎn):

1、查看網(wǎng)絡(luò)設(shè)置

2、測(cè)試網(wǎng)絡(luò)連接

3、使用網(wǎng)絡(luò)配置命令

4、修改網(wǎng)絡(luò)配置文件

二、查看網(wǎng)絡(luò)設(shè)置

1,查看網(wǎng)絡(luò)接口信息ifconfig

查看所有活動(dòng)網(wǎng)絡(luò)接口的信息

  • 執(zhí)行ifconfig命令

  • Linux基本網(wǎng)絡(luò)設(shè)置

  • 查看指定網(wǎng)路接口信息

  • ifconfig 網(wǎng)絡(luò)接口號(hào)

  • 2,查看主機(jī)名稱hostname

[root@localhost ~]# hostname? ? ? ? 查看主機(jī)名

Linux基本網(wǎng)絡(luò)設(shè)置

[root@localhost ~]# hostnamectl set-hostname http01? ?修改主機(jī)名? ?

Linux基本網(wǎng)絡(luò)設(shè)置

3,查看路由表?xiàng)l目route

route命令:查看或設(shè)置主機(jī)中路由表信息

route [-n] 或直接route

Linux基本網(wǎng)絡(luò)設(shè)置

4,查看網(wǎng)絡(luò)連接情況netstat

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

netstat [選項(xiàng)]

常用選項(xiàng)

  • -a:列出所有

  • -n:數(shù)字形式表示

  • -p:協(xié)議

  • -t:列出tcp協(xié)議連接

  • -u:列出udp協(xié)議連接

  • -r:列出路由表信息

neistat -ntap? ?查看tcp所有協(xié)議接口信息以數(shù)字形式表示

Linux基本網(wǎng)絡(luò)設(shè)置

neistat -nuap? ?查看udp所有協(xié)議接口信息以數(shù)字形式表示

Linux基本網(wǎng)絡(luò)設(shè)置

neistat -r? ? ? ? ? ? ?查看路由表信息? ? ? ? ? ? ? ? ? ?同route一樣

Linux基本網(wǎng)絡(luò)設(shè)置

三、測(cè)試網(wǎng)絡(luò)連接

a、ping命令:測(cè)試網(wǎng)絡(luò)連通性

ping [選項(xiàng)] 目標(biāo)主機(jī)

Linux基本網(wǎng)絡(luò)設(shè)置

b、跟蹤數(shù)據(jù)包 traceroute

traceroute命令:測(cè)試從當(dāng)前主機(jī)到目的主機(jī)之間經(jīng)過(guò)的網(wǎng)絡(luò)節(jié)點(diǎn)(判斷故障時(shí)使用)

tracerouter 目標(biāo)主機(jī)地址


c、域名解析nslookup

nslookup命令:測(cè)試DNS域名解析

nslookup 目標(biāo)主機(jī)地址
Linux基本網(wǎng)絡(luò)設(shè)置

四、設(shè)置網(wǎng)絡(luò)參數(shù)的方式

1、臨時(shí)配置—使用命令調(diào)整網(wǎng)絡(luò)參數(shù)

  • 簡(jiǎn)單,快速,可直接修改運(yùn)行中的網(wǎng)絡(luò)參數(shù)

  • 一般只適合在調(diào)試網(wǎng)絡(luò)的過(guò)程中使用

  • 系統(tǒng)重啟以后,所做的修改將會(huì)失效

2、固定設(shè)置—通過(guò)配置文件修改網(wǎng)絡(luò)參數(shù)

  • 修改各項(xiàng)網(wǎng)絡(luò)參數(shù)的配置文件

  • 適合對(duì)服務(wù)器設(shè)置固定參數(shù)時(shí)使用

  • 需要重載網(wǎng)絡(luò)服務(wù)或者重啟以后才會(huì)生效

1,設(shè)置網(wǎng)絡(luò)接口參數(shù)ifconfig

a、設(shè)置網(wǎng)絡(luò)接口的IP地址,子網(wǎng)掩碼(臨時(shí)設(shè)置)

ifconfig 接口號(hào) IP地址 [netmask? 子網(wǎng)掩碼]

ifconfig 網(wǎng)絡(luò)接口 IP地址[/掩碼長(zhǎng)度]

Linux基本網(wǎng)絡(luò)設(shè)置

b、禁用或者重新激活網(wǎng)卡

ifconfig 網(wǎng)絡(luò)接口 up

ifconfig 網(wǎng)絡(luò)接口 down??

Linux基本網(wǎng)絡(luò)設(shè)置

c、設(shè)置虛擬網(wǎng)絡(luò)接口(不同ip公用一個(gè)網(wǎng)卡,實(shí)現(xiàn)多個(gè)IP地址)

ifconfig 接口號(hào):序號(hào) IP地址

Linux基本網(wǎng)絡(luò)設(shè)置

2,設(shè)置路由記錄route

a、添加到指定網(wǎng)段的路由記錄

route add -net 網(wǎng)段地址 gw IP地址

Linux基本網(wǎng)絡(luò)設(shè)置

b、刪除到指定網(wǎng)段的路由記錄

route del -net 網(wǎng)段地址

Linux基本網(wǎng)絡(luò)設(shè)置

c、刪除路由表中的默認(rèn)網(wǎng)關(guān)記錄

route del default gw IP地址

?d、向路由表中添加默認(rèn)網(wǎng)關(guān)記錄

route add default gw IP地址

Linux基本網(wǎng)絡(luò)設(shè)置

五、修改網(wǎng)絡(luò)配置文件(固定設(shè)置)

a、網(wǎng)絡(luò)接口配置文件

/etc/sysconfig/network-scripts/目錄下

b、啟用,禁用網(wǎng)絡(luò)接口配置

systemctl restart network? ? ?重啟

c、禁用,啟用網(wǎng)絡(luò)接口

ifdown ens33

ifup ens33

d、域名解析配置文件

/etc/resolv.conf文件

  • 保存本機(jī)需要使用的DNS服務(wù)器的IP地址

[root@localhost ~]# vim /etc/sysconfig/network 配置主機(jī)名文件
Linux基本網(wǎng)絡(luò)設(shè)置

e、本地主機(jī)映射文件

/etc/hosts文件

  • 保存主機(jī)名與IP地址的映射記錄

hosts文件和DNS服務(wù)器的比較

  • 默認(rèn)情況下,系統(tǒng)首先從hosts文件查找解析記錄

  • hosts文件只對(duì)當(dāng)前的主機(jī)有效

  • hosts文件可減少DNS查詢過(guò)程,從而加快訪問(wèn)速度

[root@localhost ~]# vim /etc/hosts? ?配置當(dāng)前主機(jī)的dns解析

向AI問(wèn)一下細(xì)節(jié)

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

AI