linux安装基础(常用)配置
一、ip略
二、最小化安装CentOS7后, ifconfig
命令不能用。在最小化的CentOS7中,查看网卡信息的命令是:ip addr。
查看网络统计信息是:ip link。
为了方便起见 我们还是启用ifconfig
命令。
首先我们看看,是哪个组件包含了ifconfig
命令,用(此命令可能在xshell上会所没有匹配内容)
yum provides ifconfig
或yum whatprovides ifconfig
来查看
我们可以看到 ifconfig
命令是依赖于 net-tools 软件的 ,所以我们
yum install -y net-tools
安装该软件, ifconfig可以正常使用了
三、从firewalld转换为iptables
1、停止并屏蔽firewalld:
systemctl stop firewalld
systemctl disable firewalld.service //关闭firewall自动启动
systemctl mask firewalld //
系统指令 注销防火墙服务
2、
安装iptables-services:
yum install iptables-services
修改iptables配置文件
vi /etc/sysconfig/iptables
添加下面三句话到默认的22端口这条规则的下面
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
修改后的iptables配置文件:
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state –state NEW -m tcp –dport 22 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
3、设置开机启动:
systemctl enable iptables
4、停止/启动/重启 防火墙:
systemctl [stop|start|restart] iptables or service iptabels [stop|start|restart]
5、保存防火墙配置
service iptables save
查看端口
netstat -nupl (UDP类型的端口)
netstat -ntpl (TCP类型的端口)
测试端口
wget ip:端口
注:iptables的一些命令:
查询防火墙状态:
[[email protected] ~]# service iptables status
停止防火墙:
[[email protected] ~]# service iptables stop
启动防火墙:
[[email protected] ~]# service iptables start
重启防火墙:
[[email protected] ~]# service iptables restart
永久关闭防火墙:
[[email protected] ~]# chkconfig iptables off
永久关闭后启用:
[[email protected] ~]# chkconfig iptables on
开启端口:
[[email protected] ~]# vim/etc/sysconfig/iptables
四、关闭SELINUX
编辑SELINUX配置文件
vi /etc/selinux/config
#注释掉下面两行
#SELINUX=enforcing
#SELINUXTYPE=targeted
#增加一行
SELINUX=disabled
保存,关闭
setenforce 0
使设置启用,在这里最好重启一下系统,也可以稍后重启
五、CentOS7最小化安装后没有wget软件,但是以后我们会经常用到这个组件,所以我们安装一下
yum install -y wget
六、CentOS自带的国外源有时候会很慢,我们替换成国内的阿里源,也有很多比如163源都很好,国内很多人用,但这里我们就用阿里源做个示例,想用其他源的同学可以去百度一下。
#先进入源的目录
cd /etc/yum.repo.d
#备份一下官方源
mv CentOS-Base.repo CentOS-Base.repo.bak
#将阿里源文件下载下来
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#重建源数据缓存
yum makecache
ok,换源完成
七、CentOS自带vi编辑器,功能没有vim强大,我么再安装一个vim编辑器
yum install -y vim-enhanced
八、输入rz命令,看是否已经安装了lrzsz,如果没有安装则执行 yum -y install lrzsz命令进行安装。
输入 rpm -qa lrzsz 检查是否安装成功
安装成功 xshell使用命令 rz 可以直接上传文件