Linux系統(tǒng)之主機(jī)網(wǎng)絡(luò)配置方式
一、查看主機(jī)的網(wǎng)絡(luò)參數(shù)
主機(jī)名、IP地址、掩碼、網(wǎng)關(guān)、DNS服務(wù)器地址
1、查看主機(jī)名
[root@localhost ~]# hostname localhost.localdomain [root@localhost ~]# hostnamectl set-hostname martin-host.linux.com [root@localhost ~]# [root@localhost ~]# hostname martin-host.linux.com 主機(jī)名建議以FQDN格式設(shè)置
2、查看IP地址
[root@martin-host ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.140.144 netmask 255.255.255.0 broadcast 192.168.140.255
inet6 fe80::a4f5:a457:cfac:3860 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:c5:04:aa txqueuelen 1000 (Ethernet)
RX packets 1910 bytes 2214938 (2.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1090 bytes 90444 (88.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
MTU: 最大傳輸單元
RX:接收的數(shù)據(jù)流量
TX:發(fā)送的數(shù)據(jù)流量
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 1000 (Local Loopback)
RX packets 92 bytes 7800 (7.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 92 bytes 7800 (7.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@martin-host ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:c5:04:aa brd ff:ff:ff:ff:ff:ff
inet 192.168.140.144/24 brd 192.168.140.255 scope global noprefixroute dynamic ens33
valid_lft 1197sec preferred_lft 1197sec
inet6 fe80::a4f5:a457:cfac:3860/64 scope link noprefixroute
valid_lft forever preferred_lft forever3、查看網(wǎng)關(guān)
[root@martin-host ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.140.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.140.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
4、查看DNS
[root@martin-host ~]# cat /etc/resolv.conf # Generated by NetworkManager search localdomain linux.com nameserver 192.168.140.2
二、配置網(wǎng)卡
1、修改網(wǎng)卡配置文件
// 查看網(wǎng)卡的配置文件 [root@martin-host ~]# ls /etc/sysconfig/network-scripts/ ifcfg-ens33 ifdown-ipv6 ifdown-TeamPort ifup-ippp ifup-routes network-functions ifcfg-lo
[root@martin-host ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE="Ethernet" BOOTPROTO=none IPADDR=192.168.140.144 PREFIX=24 GATEWAY=192.168.140.2 DNS1=114.114.114.114 DNS2=223.5.5.5 NAME="ens33" DEVICE="ens33" ONBOOT="yes" [root@martin-host ~]# nmcli connection reload [root@martin-host ~]# nmcli connection up ens33 連接已成功激活(D-Bus 活動(dòng)路徑:/org/freedesktop/NetworkManager/ActiveConnection/7)
[root@martin-host ~]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.140.144 netmask 255.255.255.0 broadcast 192.168.140.255
inet6 fe80::20c:29ff:fec5:4aa prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:c5:04:aa txqueuelen 1000 (Ethernet)
RX packets 3622 bytes 2367174 (2.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2293 bytes 240672 (235.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@martin-host ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.140.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.140.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
[root@martin-host ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search linux.com
nameserver 114.114.114.114
nameserver 223.5.5.52、nmcli工具【通用】
- 查看網(wǎng)卡配置
[root@martin-host ~]# nmcli connection show NAME UUID TYPE DEVICE ens33 c96bc909-188e-ec64-3a96-6a90982b08ad ethernet ens33 virbr0 da62b2db-38ab-455a-bea1-a9bc9fa6f484 bridge virbr0
- 刪除網(wǎng)卡配置
[root@martin-host ~]# nmcli connection delete ens33 成功刪除連接 "ens33" (c96bc909-188e-ec64-3a96-6a90982b08ad)。
- 配置網(wǎng)卡
// 創(chuàng)建網(wǎng)卡配置,名稱為ens33 [root@localhost ~]# nmcli connection add type ethernet ifname ens33 con-name ens33 連接 "ens33" (a48997c5-50f2-4e1b-aef4-34570c36b12b) 已成功添加。 // 配置IP地址、網(wǎng)關(guān)、DNS服務(wù)器地址 [root@localhost ~]# nmcli connection modify ens33 ipv4.addresses "172.16.100.20/24" [root@localhost ~]# nmcli connection modify ens33 ipv4.gateway "172.16.100.2" [root@localhost ~]# nmcli connection modify ens33 ipv4.dns "114.114.114.114" [root@localhost ~]# nmcli connection modify ens33 +ipv4.dns "223.5.5.5" // 將網(wǎng)卡IP的配置方式改為手動(dòng)配置,默認(rèn)為dhcp [root@localhost ~]# nmcli connection modify ens33 ipv4.method manual // 設(shè)置網(wǎng)卡開機(jī)自動(dòng)激活 [root@localhost ~]# nmcli connection modify ens33 autoconnect on [root@localhost ~]# nmcli connection reload [root@localhost ~]# nmcli connection up ens33 連接已成功激活(D-Bus 活動(dòng)路徑:/org/freedesktop/NetworkManager/ActiveConnection/10)
三、vmware虛擬網(wǎng)絡(luò)工作模式
1、虛擬網(wǎng)絡(luò)、虛擬網(wǎng)卡
虛擬網(wǎng)絡(luò)
- 相當(dāng)于現(xiàn)實(shí)生活中的交換機(jī),用于連接多個(gè)虛擬機(jī),實(shí)現(xiàn)多個(gè)虛擬機(jī)的通信
- 不同虛擬網(wǎng)絡(luò)間是隔離的

虛擬網(wǎng)卡
- 每個(gè)虛擬網(wǎng)絡(luò)都會(huì)在物理機(jī)上生成一塊虛擬網(wǎng)卡
- 作用:通過(guò)虛擬網(wǎng)卡將物理機(jī)連接到了對(duì)應(yīng)的虛擬網(wǎng)絡(luò)上,用于實(shí)現(xiàn)物理機(jī)和虛擬機(jī)間的通信

2、虛擬網(wǎng)絡(luò)工作模式
NAT模式 【常用】
- NAT, 網(wǎng)絡(luò)地址轉(zhuǎn)換
- 原理:當(dāng)虛擬機(jī)主動(dòng)訪問(wèn)外部網(wǎng)絡(luò)時(shí),虛擬機(jī)的IP地址會(huì)被臨時(shí)轉(zhuǎn)換成物理機(jī)的網(wǎng)卡和外界通信
- 虛擬網(wǎng)絡(luò):Vmnet 8
- 核心依賴的服務(wù):Vmware NAT Service services.msc
- 合適的IP

橋接模式 / bridge
- 原理:虛擬機(jī)相當(dāng)于直接接入到現(xiàn)實(shí)網(wǎng)絡(luò)中
- 作用:方便不同物理機(jī)上的虛擬機(jī)間的相互通信
- 關(guān)鍵:虛擬網(wǎng)絡(luò)和哪個(gè)現(xiàn)實(shí)網(wǎng)絡(luò)建立橋接關(guān)系 ????
虛擬網(wǎng)絡(luò):vmnet 0
- 僅主機(jī)模式 / host only
- 虛擬網(wǎng)絡(luò)和外界通信是斷的
四、路由設(shè)置
1、路由器工作原理

2、靜態(tài)路由

- 配置靜態(tài)路由的命令
# route add -net 目的網(wǎng)段 gw 下一跳
3、配置靜態(tài)路由

開啟路由轉(zhuǎn)發(fā)功能
// 查看系統(tǒng)參數(shù) [root@linux-01 ~]# sysctl -a
[root@linux-01 ~]# vim /etc/sysctl.conf net.ipv4.ip_forward = 1 [root@linux-01 ~]# sysctl -p net.ipv4.ip_forward = 1
- 添加靜態(tài)路由
[root@linux-01 ~]# route add -net 192.168.18.0/24 gw 192.168.17.11 [root@linux-01 ~]# [root@linux-01 ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.16.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 192.168.17.0 0.0.0.0 255.255.255.0 U 101 0 0 ens37 192.168.18.0 192.168.17.11 255.255.255.0 UG 0 0 0 ens37
4、永久添加路由
rc.local文件
作用:開機(jī)自動(dòng)執(zhí)行文件中的操作
[root@linux-02 ~]# vim /etc/rc.d/rc.local route add -net 192.168.16.0/24 gw 192.168.17.10 [root@linux-02 ~]# chmod a+x /etc/rc.d/rc.local
創(chuàng)建路由文件
/etc/sysconfig/network-scripts/route-出接口
[root@linux-02 ~]# cat /etc/sysconfig/network-scripts/route-ens33 格式: 網(wǎng)段 via 下一跳 dev 出接口 192.168.16.0/24 via 192.168.17.10 dev ens33 [root@linux-02 ~]# nmcli connection reload [root@linux-02 ~]# nmcli connection up ens33 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3) [root@linux-02 ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.16.0 192.168.17.10 255.255.255.0 UG 102 0 0 ens33
5、測(cè)試網(wǎng)絡(luò)通信的工具
- ping
- traceroute
- 路由跟蹤
[root@node01 ~]# traceroute 192.168.18.11 traceroute to 192.168.18.11 (192.168.18.11), 30 hops max, 60 byte packets 1 gateway (192.168.16.11) 0.219 ms 0.154 ms 0.141 ms 2 192.168.17.11 (192.168.17.11) 0.439 ms 0.429 ms 0.494 ms 3 192.168.18.11 (192.168.18.11) 0.657 ms 0.634 ms 0.600 ms
[root@node01 ~]# traceroute 192.168.18.11 traceroute to 192.168.18.11 (192.168.18.11), 30 hops max, 60 byte packets 1 gateway (192.168.16.11) 0.240 ms 0.117 ms 0.070 ms 2 * * * 3 * * * 4 * * * 5 * * *
- Windows路由跟蹤
C:\Users\admin>tracert www.jd.com 通過(guò)最多 30 個(gè)躍點(diǎn)跟蹤 到 wwwv6.jcloudimg.com [124.200.112.6] 的路由: 1 2 ms 1 ms 2 ms 10.11.0.1 2 * * * 請(qǐng)求超時(shí)。 3 15 ms 4 ms 4 ms 101.39.210.93 4 7 ms 5 ms 4 ms 10.255.58.241 5 18 ms 7 ms 2 ms 10.255.60.25 6 2 ms 7 ms 4 ms 218.241.165.97 7 5 ms 2 ms 2 ms 10.240.41.185 8 3 ms 2 ms 2 ms 10.240.38.38 9 3 ms 3 ms 3 ms 10.14.224.22 10 3 ms 2 ms 2 ms 124.200.112.6 跟蹤完成。
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
詳解linux centos yum安裝LAMP環(huán)境
本篇文章主要介紹了linux centos yum安裝LAMP環(huán)境 ,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧。2016-12-12
Ubuntu/Debian 自有軟件包構(gòu)建私有源詳解
這篇文章主要介紹了Ubuntu/Debian 自有軟件包構(gòu)建私有源詳解的相關(guān)資料,這里介紹詳細(xì)步驟,需要的朋友可以參考下2016-11-11
linux時(shí)間函數(shù)與時(shí)間格式與字符串之間的轉(zhuǎn)化方法
下面小編就為大家分享一篇linux時(shí)間函數(shù)與時(shí)間格式與字符串之間的轉(zhuǎn)化方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2017-12-12
Linux監(jiān)控系統(tǒng)磁盤IO的方法匯總
在現(xiàn)代分布式系統(tǒng)和高并發(fā)服務(wù)架構(gòu)中,磁盤 I/O 性能往往是系統(tǒng)瓶頸的重要來(lái)源,本文將從基礎(chǔ)命令工具開始,逐步深入到 Java 程序如何集成磁盤監(jiān)控,最終構(gòu)建一個(gè)完整的自動(dòng)化監(jiān)控體系,需要的朋友可以參考下2026-03-03
Apache中Virtual Host虛擬主機(jī)配置及rewrite參數(shù)說(shuō)明
這篇文章主要介紹了Apache中Virtual Host虛擬主機(jī)配置及rewrite模塊中的重要參數(shù)說(shuō)明,是在同一個(gè)Apache服務(wù)器軟件上部署多個(gè)站點(diǎn)的基礎(chǔ)方法,需要的朋友可以參考下2016-03-03
Ubuntu Server 14.04升級(jí)Ubuntu Server 16.04
這篇文章主要介紹了 Ubuntu Server 14.04升級(jí)Ubuntu Server 16.04,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2016-12-12

