• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
xiaobingle
博客园    首页    新随笔    联系   管理    订阅  订阅

linux网络配置详解

备份网络文件

cp /test1/file1 /test3/file2  复制文件

 mv /test1/file1 /test3/file2  移动文件

修改固定配置文件 eth-XX

路径:cd /etc/sysconfig/network-scripts/

DEVICE=eth0        #设备名字
ONBOOT=yes        #是否随系统启动而启动
BOOTPROTO=static (dhcp) # 网络参数配置方式
IPADDR=192.168.4.1    #ip地址
NETMASK=255.255.255.0  # 子网掩码
GATEWAY=192.168.4.2    # 默认网关  可以不要
DNS1=202.106.0.20      # DNS地址 

修改主机名配置

路径:vim /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=localhost

修改DNS地址

路径:vim /etc/resolv.conf  (dns 以网络配置为准,重起网卡后会被修改掉)

nameserver 1.1.1.1

nameserver 8.8.8.8

重起网卡

service network restart   重起所有网卡

ifdown  eth0 关闭单个网卡

ifup eth0 启动当个网卡

 firewalld

1、firewalld的基本使用
启动: systemctl start firewalld
查看状态: systemctl status firewalld 
停止: systemctl disable firewalld
禁用: systemctl stop firewalld
 
2.systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。

启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service
重启一个服务:systemctl restart firewalld.service
显示一个服务的状态:systemctl status firewalld.service
在开机时启用一个服务:systemctl enable firewalld.service
在开机时禁用一个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed

3.配置firewalld-cmd

查看版本: firewall-cmd --version
查看帮助: firewall-cmd --help
显示状态: firewall-cmd --state
查看所有打开的端口: firewall-cmd --zone=public --list-ports
更新防火墙规则: firewall-cmd --reload
查看区域信息:  firewall-cmd --get-active-zones
查看指定接口所属区域: firewall-cmd --get-zone-of-interface=eth0
拒绝所有包:firewall-cmd --panic-on
取消拒绝状态: firewall-cmd --panic-off
查看是否拒绝: firewall-cmd --query-panic
 
那怎么开启一个端口呢
添加
firewall-cmd --zone=public --add-port=80/tcp --permanent    (--permanent永久生效,没有此参数重启后失效)
重新载入
firewall-cmd --reload
查看
firewall-cmd --zone= public --query-port=80/tcp
删除
firewall-cmd --zone= public --remove-port=80/tcp --permanent
 
 
xiaobingoog每天都会写博客。 留下xiaobingoog的小技术。 也许在某年的某一天, 当xiaobinggoog在次看到这个博客时, 会为当初不辞辛苦的, 只为留下这片记忆。 感谢xiaobingoog
posted @ 2018-04-24 14:52  xiaobingle  阅读(181)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3