Linux运维基础之一,基本网络的配置。
- 基本网络配置
- 防火墙配置
- 主机名称设置
1. 基本网络配置
1.1. 本地网络信息查看
- ip address 命令
- ifconfig 命令(Linux)
- ipconfig命令(Windows)
1.2. 本地网络信息配置
修改 /etc/sysconfig/network-scripts/ifcfg-eth0文件内的配置信息。具体操作内容如下:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth1
HWADDR=00:50:56:B8:05:a4
TYPE=Ethernet
UUID=ccf8fbe2-be28-40a2-b19e-7a94ce7d32bb
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.100.30
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
#修改所需的内容后进行保存
2. 防火墙基本配置
2.1 Redhat Linux 7 命令关闭防火墙
1. 查看防火墙状态
systemctl status firewalld
2. 临时关闭防火墙命令。重启电脑后,防火墙自动起来。
systemctl stop firewalld
3. 永久关闭防火墙命令。重启后,防火墙不会自动启动。
systemctl disable firewalld
4. 打开防火墙命令。
systemctl enable firewalld
5. 打开防火墙的某个对外端口(iptables 命令)
iptables -A INPUT -p -tcp -dport 22 -j ACCEPT
6. 打开防火墙的某个对外端口(firewall-cmd 命令)
firewall-cmd --add-port=2181/tcp
firewall-cmd --add-port=2888/tcp
firewall-cmd --add-port=3888/tcp
###2.2 Centos 6.4 iptables防火墙关闭启动详解
在linux中关闭防火墙有两种状态一种永久关闭防火墙,另一种是暂时关闭防火墙的方法,下面我们一起来看看具体的操作步骤。
关闭虚拟机防火墙:
关闭命令: service iptables stop
永久关闭防火墙:chkconfig iptables off
两个命令同时运行,运行完成后查看防火墙关闭状态
service iptables status
1 关闭防火墙-----service iptables stop
2 启动防火墙-----service iptables start
3 重启防火墙-----service iptables restart
4 查看防火墙状态--service iptables status
5 永久关闭防火墙--chkconfig iptables off
6 永久关闭后启用--chkconfig iptables on
永久关闭防火墙,使用命令5,reboot重启后生效; 命令1时立即生效,reboot后防火墙会重新打开。
2.3 详细操作
[root@rhel6 scripts]# systemctl status firewalld
-bash: systemctl: command not found
[root@rhel6 scripts]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
5 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
[root@rhel6 scripts]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
3. 基本网络配置
3.1 RedHat 操作系统
- 修改/etc/sysconfig/network 文件,其内容为计算机名
输入命令:vi /etc/sysconfig/network
使用键盘上的 x 键一个一个删除所有内容 ,然后使用键盘上的 i 键进入可编辑状态,输入计算机名字(不必加域名)
修改完成后,输入命令 :wq 保存退出
- 修改/etc/hosts 文件,其文件内容添加一行(修改其他的主机名称 简写找到其他计算机的配置)
xxx.xxx.xxx.xxx 计算机名字 (其中 xxx.xxx.xxx.xxx 为 IP)
输入命令: vi /etc/hosts
将光标移动到 127.0.0.1 localhost 下面一行,使用命令 i 插入内容
插入的内容为 例如:192.168.1.101 linux 其中 linux 为计算机名字
修改完成后,输入命令 :wq 保存退出
- 重新启动 linux (注:如不方便重启电脑,则可以按以下命令操作,但不一定保证成功。如不成功,请重启 linux)
输入命令:hostname 计算机名字 回车(如 hostname linux)
然后在输入:su 回车即可
参考内容
[1] 如何在linux系统中设置静态ip地址
[2] inux下查看本机IP的两种方法
[3] Linux下修改计算机名
[4] Redhat Linux 7 命令关闭防火墙
[5] Centos 6.4 iptables防火墙关闭启动详解
后记 20190324
操作CentOS
操作系统.Minal
模式安装时,是没有安装iptables
的
[root@localhost conf]# service iptables stop
Redirecting to /bin/systemctl stop iptables.service
Failed to stop iptables.service: Unit iptables.service not loaded.
centos从7开始默认用的是firewalld,这个是基于iptables的,虽然有iptables的核心,但是iptables的服务是没安装的。所以你只要停止firewalld服务即可:
sudo systemctl stop firewalld.service && sudo systemctl disable firewalld.service
如果你要改用iptables的话,需要安装iptables服务:
sudo yum install iptables-services sudo systemctl enable iptables && sudo systemctl enable ip6tables sudo systemctl start iptables && sudo systemctl start ip6tables