IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> 1 linux 中的网络配置 -> 正文阅读

[系统运维]1 linux 中的网络配置

###1.什么是IP ADDRESS
internet protocol ADDRESS??? ##网络进程地址

??ipv4???? internet protocol version 4

1.2x32
ip是由32个01组成
11111110.11111110.11111110.11111110 = 254.254.254.254

###2.子网掩码
用来划分网络区域
子网掩码非0的位对应的ip上的数字表示这个ip的网络位
子网掩码0位对应的数字是ip的主机位
网络位表示网络区域
主机位表示网络区域里某台主机

###3.ip通信判定
网络位一致,主机位不一致的2个IP可以直接通讯
172.25.254.1/24???????????? 24=255.255.255.0
172.25.254.2/24
172.25.0.1/16

####4.网络设定工具
ping?????????????????????????????????? ##检测网络是否通畅
ping -c 1? ????????????????????????? ##ping 1 次
ping -w 1????????????????????????? ##等待1秒
ping -c1 -w1 ip????????????????##ping1次等待1秒

[root@westos_student70 ~]# ping www.baidu.com       ##检查网络是否通畅
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=53 time=65.1 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=2 ttl=53 time=69.2 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=3 ttl=53 time=55.3 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=4 ttl=53 time=59.9 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=5 ttl=53 time=65.10 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=6 ttl=53 time=55.10 ms


[root@westos_student70 ~]# ping -c 1 -w 1 www.baidu.com    ##等代1秒   ping一次
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=53 time=67.8 ms

--- www.a.shifen.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms

ifconfig????????????????##查看或设定网络接口
ifconfig????????????????##查看
ifconfig device ip/24????????????????##设定
ifconfig device down????????????????##关闭
ifconfig device up???????????????????? ##开启

[root@westosa ~]# ifconfig             ##查看网卡
ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.25.254.170  netmask 255.255.255.0  broadcast 172.25.254.255
        inet6 fe80::298d:9b66:9390:8bc  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:06:67:19  txqueuelen 1000  (Ethernet)
        RX packets 1193  bytes 193347 (188.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 165  bytes 23844 (23.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

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 424  bytes 34672 (33.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 424  bytes 34672 (33.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0



[root@westosa ~]# ifconfig ens3 down  ##关闭网卡
[root@westosa ~]# 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 1000  (Local Loopback)
        RX packets 424  bytes 34672 (33.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 424  bytes 34672 (33.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0



[root@westosa ~]# ifconfig ens3 up  ##开启网卡
[root@westosa ~]# ifconfig
        inet 172.25.254.170  netmask 255.255.255.0  broadcast 172.25.254.255
        inet6 fe80::298d:9b66:9390:8bc  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:06:67:19  txqueuelen 1000  (Ethernet)
        RX packets 1193  bytes 193347 (188.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 165  bytes 23844 (23.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

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 424  bytes 34672 (33.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 424  bytes 34672 (33.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ip addr?? ##检测或这顶网络接口
ip addr? show??? ##检测
ip addr? add ip/24 dev device??? ##设定
ip addr? del dev ens160 ip/24? ##删除

[root@westosa ~]# ip addr add 172.25.254.175/24 dev ens3  ##建立新的ip
[root@westosa ~]# ip addr show
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: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:06:67:19 brd ff:ff:ff:ff:ff:ff
    inet 172.25.254.170/24 brd 172.25.254.255 scope global noprefixroute ens3
       valid_lft forever preferred_lft forever
    inet 172.25.254.175/24 scope global secondary ens3
       valid_lft forever preferred_lft forever
    inet6 fe80::298d:9b66:9390:8bc/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever



[root@westosa ~]# ip addr delete 172.25.245.175/24 dev ens3   ##删除ip
RTNETLINK answers: Cannot assign requested address
[root@westosa ~]# ip addr show
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: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:06:67:19 brd ff:ff:ff:ff:ff:ff
    inet 172.25.254.170/24 brd 172.25.254.255 scope global noprefixroute ens3
       valid_lft forever preferred_lft forever
    inet6 fe80::298d:9b66:9390:8bc/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

####5.图形方式设定ip


设定:
1.nm-connection-editor

#添加连接
nmcli connection add type ethernet con-name westos ifname ens160 ? ip4 172.25.254.100/24

#更改
nmcli connection modify westos? ipv4.addresses 172.25.254.200/24


更改:
不建议用服务控制网络
systemctl restart NetworkManager


建议使用:
nmcli connection show
nmcli connection down westos
nmcli connection up westos

2.nmtui
####6.命令方式设定网络
nmcli????????????????##NetworkManager必须开启

nmcli????????connection????????show????????????????##查看连接
nmcli????????connection????????down ens3 ????? ##关闭连接
nmcli????????connection????????up ens3 ????????????? ##开启连接
nmcli????????connection????????delete ens3 ?????? ##删除连接





[root@westosa ~]# nmcli connection show   ##查看
NAME  UUID                                  TYPE      DEVICE 
ens3  45deaabe-f323-4b25-bade-9ccf0a24a776  ethernet  ens3  
  
[root@westosa ~]# nmcli connection down ens3   ##关闭

[root@westosa ~]# nmcli connection show
NAME  UUID                                  TYPE      DEVICE 
ens3  45deaabe-f323-4b25-bade-9ccf0a24a776  ethernet  --

[root@westosa ~]# nmcli connection up ens3     ##开启
[root@westosa ~]# nmcli connection show
NAME  UUID                                  TYPE      DEVICE 
ens3  45deaabe-f323-4b25-bade-9ccf0a24a776  ethernet  ens3  

####8.lo回环接口
回环接口------人的神经----127.0.0.1-----localhost

####9.网关#####

vim /etc/sysconfig/network????????????????##全局网关,针对所有没有设定网关的网卡生效
GATEWAY=172.25.254.250

vim /etc/sysconfig/network-scripts/ifcfg-ens160????????????????##档网卡中设定的IP有多个时,指定对于那个IP生效
GATEWAY0=172.25.254.20

GATEWAY=172.25.254.20????????????????##档网卡中设定的IP只有一个时

route -n???? ##查看网关????????

Destination????????????????Gateway????????????????Genmask????????????????Flags??? Metric????????Ref??????????UseIface??????
0.0.0.0??????? ? ? ? ? ? ? ? ? ? 172.20.10.2? ? ? ? ? 0.0.0.0?????? ? ? ? ? ? ? ? ? UG??? 100?? ? ? ? ? ?? 0??????? 0 ens3
1.1.1.0?????? ? ? ? ? ? ? ? ? ? ? ?? 0.0.0.0???????? 255.255.255.0? ? ? ? ? ? ? ? ? U???? 100?? ? ? ? ? ?? 0??????? 0 ens3
172.20.10.2??????????????????? 0 .0.0.0???????? 255.255.255.255 ? ? ? ? ?? UH??? 100 ? ? ? ? ?? ? 0??????? 0 ens3
172.25.254.0?????????????????? 0.0.0.0???????? 255.255.255.0 ? ? ? ? ? ? ? ?? U???? 100?? ? ? ? ? ?? 0??????? 0 ens3

cd /etc/sysconfig/network-scripts
ls
ifcfg-westos
vim  ifcfg-westos
[root@westosa network-scripts]# cat ifcfg-westos
DEVICE=ens3
ONBOOT=yes
BOOTPROTO=none
IPADDR0=172.25.254.170
NETMASK0=255.255.255.0
IPADDR1=1.1.1.170
PREFIX1=24
NAME=westos
GATEWAY0=172.20.10.2

[root@westosa ~]# vim /etc/sysconfig/network

[root@westosa ~]# cat /etc/sysconfig/network
# Created by anaconda
# GATEWAY=172.20.10.2


firewall-cmd --add-masquerade  配置防火墙 添加地址伪装

nmcli connection reload
nmcli connection up westos

##11.设定解析的优先级系统默认:
/etc/hosts??? >??? /etc/resolv.conf
vim /etc/nsswitch.conf
39 hosts:???? files dns???????? # #/etc/hosts优先
vim /etc/nsswitch.conf
39 hosts:????????????? dns files????????? ##/etc/resolv.conf dns指向优先

####12.dhcp服务配置

在主机中使用景象找到dhcp-server的安装包
rpm -ivh dhcp-server

cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf ##用模板生成配置文件
vim /etc/dhcp/dhcpd.conf

# dhcpd.conf

# Sample configuration file for ISC dhcpd

# option definitions common to all supported networks...

option domain-name "westos.com"???????????? ##域名

option domain-name-servers 114.114.114.114;?????????

##dnsdefault-lease-time 600;?????? ##默认租约
max-lease-time 7200;?????????????????? ##最长租约

# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
#Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.

27???? 删除
28??????? 删除

# This is a very basic subnet declaration.
subnet 172.25.254.0 netmask 255.255.255.0 {???????? ##子网设定
range 172.25.254.160 172.25.254.200;????????????????? ##IP地址池
option routers 172.25.254.250;???????????????? ##网关

}

35行有面全删除

systemctl restart dhcpd
systemctl stop firewalld

测试:
在网络工作模式是dhcp的主机中重启网络
可以看到
ip
GW
dns
全部获取成功

  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2021-07-23 11:14:16  更:2021-07-23 11:15:21 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年4日历 -2024/4/28 5:49:56-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码