zoukankan      html  css  js  c++  java
  • Linux系统网络参数设置


    Linux系统网络参数设置


    计算机名称 
    IP地址
    子网掩码
    默认网关
    DNS服务器
    

    1、计算机名称

    CentOS 7:

    hostnamectl set-hostname node01.linux.com [FQDN 完全合格域名]
    cat /etc/hostname

    CentOS 6:

    hostname node02.linux.com

    vim /etc/sysconfig/network

    IP地址 192.168.122.105 点分十进制表示法

    组成:32位二进制数字

    xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx

    0--255 0--255 0-255 0-255 0.0.0.0 ---- 255.255.255.255

    类型:

    1. 根据第一个字节的取值范围分类

    A类:0---127
    B类:128--191
    C类:192--223 单播地址 Unicast 同一个网络内,一个IP地址只能标识一个网络节点
    D类:224--239 组播地址 Multicast
    E类:240--255 科学研究

    1. 根据IP地址的使用范围

    私网地址
    10.0.0.0---------10.255.255.255
    172.16.0.0-------172.31.255.255
    192.168.0.0------192.168.255.255
    公网地址

    特殊地址:

    127.x.x.x      127.0.0.1 
    
    169.254.x.x 		
    

    子网掩码 netmask

    作用:判断多个地址是否属于同一个网络

    原理:分别将IP地址与子网掩码转换为二进制数字,依次进行逻辑与运算(网段)

    默认子网掩码:

    A类: 255.0.0.0 /8
    B类: 255.255.0.0 /16
    C类: 255.255.255.0 /24

    192.168.1.1 255.255.255.0 ====> 192.168.1.1/24(CIDR)

    OSI七层模型

    应用层	表示层	会话层	传输层	网络层	数据链路层	物理层 
    

    数据封装过程:
    MAC帧头+IP报头+TCP/UDP报头+数据

    	TCP/UDP报头:
    		端口号  Port, 区分不同的应用程序
    		取值范围:1---65535 基于IP地址
    

    CentOS 7 提供network、NetworkManager服务实现网络参数

    基于network服务

    1、查看操作

    1. 查看网卡IP地址

    ifconfig

    ip addr show

    1. 查看网关

    [root@test01 ~]# route -n

    1. 查看DNS服务器地址

    [root@test01 ~]# cat /etc/resolv.conf

    Generated by NetworkManager

    search linux.com
    nameserver 192.168.122.1

    修改网卡TCP/IP参数

    网卡配置文件路径:
    /etc/sysconfig/network-scripts/ifcfg-*

    内容:

    DEVICE=网卡名称
    NAME=网卡配置文件名称
    ONBOOT=yes //设置开机自动启动网卡
    BOOTPROTO=none //手工指定IP
    IPADDR=192.168.122.105
    NETMASK=255.255.255.0 或 PREFIX=24
    GATEWAY=192.168.122.1
    DNS1=114.114.114.114
    DNS2=202.106.0.20

    示例:

    [root@test01 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0

    Generated by dracut initrd

    DEVICE=eth0
    NAME="eth0"
    ONBOOT=yes
    NETBOOT=yes
    BOOTPROTO=none
    IPADDR=192.168.122.105
    NETMASK=255.255.255.0
    GATEWAY=192.168.122.1
    DNS1=192.168.122.1
    DNS2=202.106.0.20
    TYPE=Ethernet

    [root@test01 ~]# systemctl restart NetworkManager
    [root@test01 ~]# systemctl restart network

    示例:为eth0网卡配置多个IP地址 10.1.1.1/24

    临时生效:

    [root@test01 ~]# ifconfig eth0:0 10.1.1.1/24

    [root@test01 ~]# ip addr add dev eth0 10.1.1.1/24

    永久生效:

    [root@test01 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0:0

    DEVICE=eth0:0
    NAME=eth0:0
    ONBOOT=yes
    BOOTPROTO=none
    IPADDR=10.1.1.1
    PREFIX=24

    [root@test01 ~]# systemctl restart NetworkManager
    [root@test01 ~]# systemctl restart network

    临时禁用网卡

    ifdown 网卡名称

    启用网卡

    ifup 网卡名称

    基于NetworkManager服务 --- nmcli

    [root@test01 ~]# nmcli connection add type ethernet ifname ens15 con-name ens15 >>>创建配置文件

    [root@test01 ~]# nmcli connection modify ens15 ipv4.addresses "10.0.0.1/24"
    [root@test01 ~]# nmcli connection modify ens15 ipv4.gateway "10.0.0.25"
    [root@test01 ~]# nmcli connection modify ens15 ipv4.dns "114.114.114.114"
    [root@test01 ~]# nmcli connection modify ens15 ipv4.method manual >>>将获取IP的方式修改为手动

    [root@test01 ~]# nmcli connection reload >>>>重新加载配置
    [root@test01 ~]# nmcli connection up ens15 >>>>激活网卡

    查看操作

    1、查看网卡的配置文件

    [root@test01 ~]# nmcli connection show

    2、查看设备信息

    [root@test01 ~]# nmcli device show ens15

    3、删除网卡的配置文件

    [root@test01 ~]# nmcli connection delete Wired connection 1

    显示网卡的状态及速率

    [root@localhost ~]# ethtool enp2s0

    端口号 Port

    1. 查看TCP端口

    [root@test01 ~]# ss -antp

    [root@test01 ~]# netstat -antp

    1. 查看UDP端口

    [root@test01 ~]# ss -anup

    [root@test01 ~]# netstat -anup

    链接: https://pan.baidu.com/s/1cCL746 密码: 8fgf

    链接: https://pan.baidu.com/s/1gfdz6l9 密码: xndg

    链接: https://pan.baidu.com/s/1crMMQU 密码: wfbp

    有志者,事竟成,破釜沉舟,百二秦关终属楚; 苦心人,天不负,卧薪尝胆,三千越甲可吞吴。 想到与得到中间还有两个字——做到。
  • 相关阅读:
    activemq的两种基本通信方式的使用及总结
    EJBCA认证系统结构及相关介绍
    白话经典算法系列之一 冒泡排序的三种实现 【转】
    springcloud配置需要主要的地方
    Spring的RestTemplate
    mysql中的事务
    list去重
    webpack的使用
    rocketmq在linux搭建双master遇到的坑
    redis配置文件详解
  • 原文地址:https://www.cnblogs.com/huoxc/p/12850970.html
Copyright © 2011-2022 走看看