Linux网络配置学习总结

版权声明:本文为博主原创文章,转载请注明原创链接! https://blog.csdn.net/qq_39112646/article/details/89074382

一:主机名及设置

1. hostname

功能:显示和临时设置主机名

注:hostname设置的主机名没有被保存到/etc/hostname,下次重启失效

2. hostnamectl

功能:用于查询和设置主机名

eg:
    hostnamectl 显示当前主机的设置信息
    hostnamectl set-hostname name  设置主机名为name

二:网卡命名

Linux对传统的以太网命名采用的是eth#的办法,如eth0,eth1

在引入systemd之后,命名变成 eno1677736 ens33 enp7s0 wlp3s0
    前两个字符
        en:以太网 ethernet
        wl:无线局域网 wlan
        ww:无线广域网 wwan
    第三个以及之后的字符
        o<index>    内置网卡,index为编号
        s<slot>     外置网卡,slot为热插拔口编号
        p<bus>s<slot>     pci几何位置

三:网络配置文件

1.通用的TCP/文件

/etc/hosts    把域名和IP对应起来的文本文件
/etc/services 服务和端口/协议的定义文件 
/etc/resolv.conf    域名服务器定义文件
/etc/networks       定义子网
/etc/hostname 系统的静态主机名,系统启动时读取这个文件,然后设置主机名

2. 红帽系统

主要配置目录 /etc/sysconfig目录

/etc/sysconfig/network-scripts的ifcfg-<interface>  网卡配置文件(配置静态IP)

/etc/init.d/network     传统的网络服务管理脚本
    /etc/init.d/netword    start  启动网络
    /etc/init.d/netword    stop    停止网络
    /etc/init.d/netword    restart 重启网络

ifup  网卡名    启动网卡
ifdown 网卡名    关闭网卡

3. Ubuntu系统 

/etc/network/interfaces 配置文件,定义每一个网络接口
    iface 网络接口 网络协议 配置方式   用于配置一个网络接口
    auto    启动一个网络接口
    source /etc/network/interferces.d/*    从别的文件包含配置信息

一个设置eth0网卡静态IP地址的/etc/network/interfaces文件内容如下
    auto lo    自动启用回送
    iface lo inet loopback 内部回送网络接口  (不使用dhcp默认只要这个两行)

    auto etho     ifup运行,系统自动启动auth0
    iface eth0 inet static  eth0 ipv4地址静态分配
    iface eth0 inet6 auto   eth0 ipv6 自动分配
    address *.*.*.*    IP地址
    netmask *.*.*.*    子网掩码
    gateway *.*.*.*    网关地址  

/etc/init.d/networking     传统的网络服务管理脚本
    /etc/init.d/networking    start    启动网络
    /etc/init.d/networking    stop    停止网络
    /etc/init.d/networking    restart 重启网络

ifup   网卡名    启动网卡
ifdown 网卡名    关闭网卡

猜你喜欢

转载自blog.csdn.net/qq_39112646/article/details/89074382