您的当前位置:首页>全部文章>文章详情

Linux系统之【防火墙】及【网络配置】

发表于:2022-12-21 12:55:41浏览:369次TAG: #Linux

## 网络地址配置

静态IP配置(centos7)

静态IP配置(debian)

下面命令查看目前IP地址及配置
 debian11:~$ ip addr
 修改下面配置文件即可改为静态IP配置
 debian11:~$ vim /etc/network/interface
 查看主要网络接口 enp0s3,默认自动获取IP是如下配置
    allow-hotplug enp0s3 
    iface enp0s3 inet dhcp
 改成静态IP改成如下配置,找到上面对应的 allow-hotplug enp0s3 修改内容
    auto enp0s3
    iface enp0s3 inet static
    address 192.168.1.102
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-domain seet.home //注意这个没具体体验效果以后再说
    dns-nameservers 192.168.1.1 //DNS服务器直接配置给网关路由也可以

警告:不要通过基于ssh的会话运行以下内容,否则会断开连接。不要在ssh会话上运行以下命令,因为你会断开连接。

请使用systemctl命令,如下所示。

debian11:~$ sudo systemctl restart networking.service.

确保服务重新启动时没有任何错误。因此,键入以下命令。

debian11:~$ sudo systemctl status networking.service

## 开启SSH远程登录

1,安装ssh-service
apt install ssh
2,修改配置文件目录 
vim /etc/ssh/sshd_config
3,修改如下
PermitRootLogin yes
4,重启服务
systemctl restart ssh

## 防火墙操作

开启端口(centOS7)

##获取当前域
firewall-cmd –get-active-zones

##根据上面的域(结果:public)运行开启命令, permanent为端口开启持久化
firewall-cmd –zone=public –add-port=6379/tcp –permanent

##保存重新载入更改
firewall-cmd –reload

查看端口号是否开启,运行命令:
firewall-cmd –query-port=6379/tcp

开启端口(debian)

##安装iptables
 apt-get update
 apt-get install iptables
##配置端口:入站端口
 iptables -I INPUT -p tcp --dport 8888 -j ACCEPT
##保存规则:
 iptables-save
##为了重启生效:
 apt-get install iptables-persistent
 netfilter-persistent save
 netfilter-persistent reload