Linux的网络

简介: 主机名的配置

主机名的配置


oracle@yaoyuan ~$ cat /etc/hosts127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4::1         localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.56.107 yuan yuan.yaoyuanoracle@yaoyuan ~$ hostnameyuan.yaoyuanoracle@yaoyuan ~$ cat /etc/hostname yuan.yaoyuanoracle@yaoyuan ~$ ping yuanPING yuan (192.168.56.107) 56(84) bytes of data.64 bytes from yuan (192.168.56.107): icmp_seq=1 ttl=64 time=0.071 ms64 bytes from yuan (192.168.56.107): icmp_seq=2 ttl=64 time=0.057 ms^C--- yuan ping statistics ---2 packets transmitted, 2 received, 0% packet loss, time 1039msrtt min/avg/max/mdev = 0.057/0.064/0.071/0.007 msoracle@yaoyuan ~$ ping yuan.yaoyuanPING yuan (192.168.56.107) 56(84) bytes of data.64 bytes from yuan (192.168.56.107): icmp_seq=1 ttl=64 time=0.072 ms64 bytes from yuan (192.168.56.107): icmp_seq=2 ttl=64 time=0.075 ms^C--- yuan ping statistics ---2 packets transmitted, 2 received, 0% packet loss, time 1017msrtt min/avg/max/mdev = 0.072/0.073/0.075/0.008 ms


02

ifconfig


ifconfig命令用于显示或设置网络设备,还可设置网络设备的状态,或是显示目前的设置。

显示网络设备信息和配置IP地址



# ifconfig ...# ifconfig eth0 192.168.1.56 //给eth0网卡配置IP地址# ifconfig eth0 192.168.1.56 netmask 255.255.255.0 // 给eth0网卡配置IP地址,并加上子掩码# ifconfig eth0 192.168.1.56 netmask 255.255.255.0 broadcast 192.168.1.255// 给eth0网卡配置IP地址,加上子掩码,加上个广播地址

查看网络配置文件




oracle@yaoyuan ~$ cat /etc/sysconfig/network-scripts/ifcfg-enp0s8TYPE=EthernetPROXY_METHOD=noneBROWSER_ONLY=no...

配置网卡信息

配置网络服务的工作其实就是在编辑网卡配置文件

vim /etc/sysconfig/network-scripts/ifcfg-ens33

➢ 设备类型:TYPE=Ethernet

➢ 地址分配模式:BOOTPROTO=static

➢ 网卡名称:NAME=eno16777736

➢ 是否启动:ONBOOT=yes

➢ IP 地址:IPADDR=192.168.10.10

➢ 子网掩码:NETMASK=255.255.255.0

➢ 网关地址:GATEWAY=192.168.10.1

➢ DNS 地址:DNS1=192.168.10.1

修改了网络配置后,重新启动网络服务:systemctl restart network

关注ONBOOT、IPADDR等

03

nmtui工具

文本方式的配置网络界面

配置完成后重新启动网络:systemctl restart network


04

ip工具


ip命令也可以用于配置ip地址和激活网卡



# ip addr...# ip --help...ethtool


05

ethtool工具


ethtool 是用于查询及设置网卡参数的命令。

ethtool ethx       //查询ethx网口基本设置,其中 x 是对应网卡的编号,如eth0、eth1等等





oracle@yaoyuan ~$ ethtool em1 Settings for em1:  Supported ports: [ TP ]  Supported link modes:   10baseT/Half 10baseT/Full                           100baseT/Half 100baseT/Full                           1000baseT/Half 1000baseT/Full   Supported pause frame use: No  Supports auto-negotiation: Yes  Supported FEC modes: Not reported  Advertised link modes:  10baseT/Half 10baseT/Full                           100baseT/Half 100baseT/Full                           1000baseT/Half 1000baseT/Full   Advertised pause frame use: Symmetric  Advertised auto-negotiation: Yes  Advertised FEC modes: Not reported  Link partner advertised link modes:  10baseT/Half 10baseT/Full                                        100baseT/Half 100baseT/Full                                        1000baseT/Full   Link partner advertised pause frame use: No  Link partner advertised auto-negotiation: Yes  Link partner advertised FEC modes: Not reported  Speed: 1000Mb/s  Duplex: Full  Port: Twisted Pair  PHYAD: 1  Transceiver: internal  Auto-negotiation: on  MDI-X: offCannot get wake-on-lan settings: Operation not permitted  Current message level: 0x000000ff (255)             drv probe link timer ifdown ifup rx_err tx_err  Link detected: yesoracle@yaoyuan ~$ ethtool p5p1Settings for p5p1:  Supported ports: [ FIBRE ]  Supported link modes:   1000baseT/Full                           10000baseT/Full   Supported pause frame use: Symmetric  Supports auto-negotiation: Yes  Supported FEC modes: Not reported  Advertised link modes:  1000baseT/Full                           10000baseT/Full   Advertised pause frame use: Symmetric  Advertised auto-negotiation: Yes  Advertised FEC modes: Not reported  Speed: 10000Mb/s  Duplex: Full  Port: FIBRE  PHYAD: 0  Transceiver: internal  Auto-negotiation: onCannot get wake-on-lan settings: Operation not permitted  Current message level: 0x00000007 (7)             drv probe link  Link detected: yes

关注Link detected是否接网线,Speed速度:千兆网或者万兆网。上面两个例子第一个是千兆网第二个是万兆网

当服务器有多个网卡并且已经配置好运行当中,你却没记得eth0、eth1、eth2.....分别对应的是哪个物理的网卡,此时可以使用如下命令:

ethtool -p eth0

此时就会看到 eth0 对应的物理口一个灯在不停地闪烁,对了。这就是我们在系统看到的那个叫eth0的网卡了,就是这么简单。按ctrl+ c停止。


06

ping和telnet工具


测试到一个远端的ip通或者不同通常用ping,测试端口用telnet。


oracle@yaoyuan ~$ ping 192.168.56.107PING 192.168.56.107 (192.168.56.107) 56(84) bytes of data.64 bytes from 192.168.56.107: icmp_seq=1 ttl=64 time=0.072 ms64 bytes from 192.168.56.107: icmp_seq=2 ttl=64 time=0.038 ms^C--- 192.168.56.107 ping statistics ---2 packets transmitted, 2 received, 0% packet loss, time 1002msrtt min/avg/max/mdev = 0.038/0.055/0.072/0.017 msoracle@yaoyuan ~$ telnet 192.168.56.107 1521Trying 192.168.56.107...Connected to 192.168.56.107.
相关文章
|
7天前
|
iOS开发 MacOS Windows
|
1天前
|
网络协议 Linux 网络架构
|
4天前
|
域名解析 网络协议 Linux
linux网络配置详解
linux网络配置详解
14 0
|
5天前
|
网络协议 Java Linux
【探索Linux】P.29(网络编程套接字 —— 简单的TCP网络程序模拟实现)
【探索Linux】P.29(网络编程套接字 —— 简单的TCP网络程序模拟实现)
12 0
|
5天前
|
存储 网络协议 算法
【探索Linux】P.28(网络编程套接字 —— 简单的UDP网络程序模拟实现)
【探索Linux】P.28(网络编程套接字 —— 简单的UDP网络程序模拟实现)
11 0
|
5天前
|
网络协议 算法 Linux
【探索Linux】P.27(网络编程套接字 —— UDP协议介绍 | TCP协议介绍 | UDP 和 TCP 的异同)
【探索Linux】P.27(网络编程套接字 —— UDP协议介绍 | TCP协议介绍 | UDP 和 TCP 的异同)
14 0
|
5天前
|
存储 算法 网络协议
【探索Linux】P.26(网络编程套接字基本概念—— socket编程接口 | socket编程接口相关函数详细介绍 )
【探索Linux】P.26(网络编程套接字基本概念—— socket编程接口 | socket编程接口相关函数详细介绍 )
12 0
|
5天前
|
存储 网络协议 Unix
【探索Linux】P.25(网络编程套接字基本概念 —— 预备知识)
【探索Linux】P.25(网络编程套接字基本概念 —— 预备知识)
6 0
|
5天前
|
网络协议 Linux 数据安全/隐私保护
【探索Linux】P.24(网络基础)
【探索Linux】P.24(网络基础)
16 0
|
6天前
|
网络协议 Linux 开发工具
Linux中 /etc/sysconfig/network-scripts/ifcfg-<interface> 网络接口配置 详解 看这一篇够用
Linux中 /etc/sysconfig/network-scripts/ifcfg-<interface> 网络接口配置 详解 看这一篇够用