Linux网络基本配置命令

修改方法:

  • 命令方式,大多是立即生效、临时有效;
  • GUI图形方式,
  • 修改配置文件,重启服务有效

1、修改主机名

hostname查看
hostname name临时修改
hostnamectl set-hostname name永久有效(cnetos7)
centos7 /etc/hostname
centos6 /etc/sysconfig/network

2、网络接口配置

  • vi修改配置文件
  • ifconfig查看或设置网卡的TCP/IP参数
[lixn@localhost ~]$ ifconfig
enp0s31f6: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500        enp0/etho第一块物理网卡    mtu分组的最大传送单元  flags网络接口状态up....(活动)
        inet 192.168.1.125  netmask 255.255.255.0  broadcast 192.168.1.255   inet/inet addr网卡的IP地址   netmask/Mask子网掩码    boadcast/bcast广播地址
        inet6 fe80::c133:9f47:a9f:66  prefixlen 64  scopeid 0x20<link>    ine网卡IPv6
        ether c8:5b:76:25:af:01  txqueuelen 1000  (Ethernet)          ether/Hwaddr网卡的物理地址mac地址  txqueuelen传送队列的长度
        RX packets 4673305  bytes 3223334449 (3.0 GiB)             RX packets接受的数据包总数
        RX errors 0  dropped 0  overruns 0  frame 0               
        TX packets 2439350  bytes 305949223 (291.7 MiB)             TX packets发送的数据包总数
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  memory 0xe1300000-e1320000  

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 1  (Local Loopback)
        RX packets 45571  bytes 3060724 (2.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 45571  bytes 3060724 (2.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlp1s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether b8:81:98:5a:7f:17  txqueuelen 1000  (Ethernet)
        RX packets 1284454  bytes 1267419395 (1.1 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 913186  bytes 155893700 (148.6 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
当前有3个网络接口信息,一个是enp0是系统的第一块网卡信息;lo代表loopback环回接口,是Linux内部通信的基础,IP始终为127.0.0.1;
ifconfig 网卡名 <IP地址> netmask <子网掩码>  此命令会立即生效,但不会修改配置文件。
ifconfig eth0 192.168.1.10 netmask 255.255.255.0  设置网卡
ifconfig eth0:1 192.168.1.10 netmask 255.255.255.0  eth0:1为设置虚拟网卡

 mac地址,全球唯一,由网络设备制造商生产时写入网卡内部。mac地址长度为48位的十六进制数,用冒号分割 c8:5b:76:25:af:01,前六为为网卡制造商编号,后六位为系列号。要更改mac地址,需要先禁用该网卡,然后使用ifconfig

ifconfig 网卡名 down禁用网卡
ifconfig 网卡名 hw ether c8:5b:76:25:af:01修改网卡
ifconfig 网卡名 up启用网卡

永久修改网卡配置文件要去/etc/sysconfig/network-scripts/ifcfg-eth0, 然后重启网络服务network

ip addr命令看到的是啥??

 

此外还有图形配置方法!(菜单; system-config-network命令; system-config-network-tui命令)

 

监控网络:iftop -i eno1 -P

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值