Linux网络服务之网络设置相关命令

发布时间:2024-11-23 点击:126
系统运维
linux网络设置
查看网络设置
测试网络连接
使用网络配置命令
修改网络配置文件
? 本文主要介绍linux中一些基础常用的linux网络设置命令与一些脚本文件配置步骤。
一、查看及测试网络配置
1.ifconfig——查看网络接口地址
格式:ifconfig [网络接口名] [ip地址](子网掩码)
[root@lokott ~]# ifconfigens33: flags=4163<up,broadcast,running,multicast> mtu 1500 inet 192.168.68.130 netmask 255.255.255.0 broadcast 192.168.68.255 inet6 fe80::7eb1:2dde:8a54:6927 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:56:d3:4a txqueuelen 1000 (ethernet) rx packets 3556 bytes 232528 (227.0 kib) rx errors 0 dropped 0 overruns 0 frame 0 tx packets 104 bytes 16400 (16.0 kib) tx errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: 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 56 bytes 6144 (6.0 kib) rx errors 0 dropped 0 overruns 0 frame 0 tx packets 56 bytes 6144 (6.0 kib) tx errors 0 dropped 0 overruns 0 carrier 0 collisions 0virbr0: flags=4099<up,broadcast,multicast> mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:71:37:09 txqueuelen 1000 (ethernet) rx packets 0 bytes 0 (0.0 b) rx errors 0 dropped 0 overruns 0 frame 0 tx packets 0 bytes 0 (0.0 b) tx errors 0 dropped 0 overruns 0 carrier 0 collisions 0[root@lokott ~]# ifconfig ens33ens33: flags=4163<up,broadcast,running,multicast> mtu 1500 inet 192.168.68.130 netmask 255.255.255.0 broadcast 192.168.68.255 inet6 fe80::7eb1:2dde:8a54:6927 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:56:d3:4a txqueuelen 1000 (ethernet) rx packets 3560 bytes 232768 (227.3 kib) rx errors 0 dropped 0 overruns 0 frame 0 tx packets 104 bytes 16400 (16.0 kib) tx errors 0 dropped 0 overruns 0 carrier 0 collisions 02.hostname ——查看主机名
格式:hostname
[root@lokott ~]# hostnamelokott[root@lokott ~]# cat /etc/hostnamelokott[root@lokott ~]# echo local > /etc/hostname [root@lokott ~]# cat /etc/hostnamelocal[root@lokott ~]#需要重启才可以设置成功,另一种方法是使用hostnamectl set-hostname 主机名^c[root@lokott ~]#reboot[root@local ~]# hostnamectl set-hostname lokott[root@local ~]# su[root@lokott ~]# 换为lokott了^c3.route——查看路由条目
-n:数字显示(centos6中,7中加不加几乎一样)
[root@lokott ~]# routekernel ip routing tabledestination gateway genmask flags metric ref use ifacedefault gateway 0.0.0.0 ug 100 0 0 ens33192.168.68.0 0.0.0.0 255.255.255.0 u 100 0 0 ens33192.168.122.0 0.0.0.0 255.255.255.0 u 0 0 0 virbr0[root@lokott ~]# route -nkernel ip routing tabledestination gateway genmask flags metric ref use iface0.0.0.0 192.168.68.2 0.0.0.0 ug 100 0 0 ens33192.168.68.0 0.0.0.0 255.255.255.0 u 100 0 0 ens33192.168.122.0 0.0.0.0 255.255.255.0 u 0 0 0 virbr04.netstat——查看网络连接情况
-n 序列号
-p 端口号
-a 所有服务端口
-r 显示路由表信息
-l 显示处于监听状态的网络连接及端口信息
-t tcp
-u udp
[root@lokott ~]# netstat -natpactive internet connections (servers and established)proto recv-q send-q local address foreign address state pid/program name tcp 0 0 0.0.0.0:111 0.0.0.0:* listen 1/systemd tcp 0 0 192.168.122.1:53 0.0.0.0:* listen 1490/dnsmasq tcp 0 0 0.0.0.0:22 0.0.0.0:* listen 941/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* listen 939/cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* listen 1186/master tcp6 0 0 :::111

买企业邮箱
因原有账号所有人裘燕红为公司离职人员
阿里云ecs服务器怎么购买最划算
开通的企业邮箱为什么不能用
提交法人照片-备案平台
云服务器到期需要重新备案吗
阿里云服务器租用多少钱一年
docker容器怎么开端口