云服务器Centos6.8安装配置samba文件共享

来源:互联网 发布:淘宝返利网站 编辑:程序博客网 时间:2024/06/06 06:50

[阿里云服务 CentOS7 Samba安装]

因为阿里云CentOS7服务器默认的防火墙是firewalle,且samba和vsftp相关端口都是关闭的
先安装iptables 配置相关rule, 然后配置samba。

PS:结合大家的分享整理一下自己安装过程。

 

一、iptables 配置


1、安装iptables
#先检查是否安装了iptables
service iptables status

#安装
yum -y install iptables
#升级
yum update iptables
#安装 iptables-services
yum -y install iptables-services

2、禁用/停止自带的firewalld服务
systemctl stop firewalld
systemctl mask firewalld


3、添加&保存iptables 规则

#查看iptables现有规则
iptables -L -n
#先允许所有,不然有可能会杯具
iptables -P INPUT ACCEPT
#清空所有默认规则
iptables -F
#清空所有自定义规则
iptables -X
#所有计数器归0
iptables -Z
#允许来自于lo接口的数据包(本地访问)
iptables -A INPUT -i lo -j ACCEPT


#开放22端口 21(FTP) 80(HTTP) 443(HTTPS)
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT

#samba相关端口
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT 
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT
iptables -A INPUT -m state --state NEW -m udp -p udp --dport 137 -j ACCEPT
iptables -A INPUT -m state --state NEW -m udp -p udp --dport 138 -j ACCEPT
#iptables -A INPUT -p tcp --dport 8089 -j ACCEPT

#允许ping
iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
#允许接受本机请求之后的返回数据 RELATED,是为FTP设置的
iptables -A INPUT -m state --state  RELATED,ESTABLISHED -j ACCEPT
#其他入站一律丢弃
iptables -P INPUT DROP
#所有出站一律绿灯
iptables -P OUTPUT ACCEPT
#所有转发一律丢弃
iptables -P FORWARD DROP

#保存上述规则
service iptables save


4、开启iptables服务
#注册iptables服务 相当于chkconfig iptables on
systemctl enable iptables.service
#开启服务
systemctl start iptables.service
#查看状态
systemctl status iptables.service


二、samba安装&配置

首先需要配置共享文件夹的路径,这里配置的是  /home/work 
1、安装
rpm -qa | grep samba
yum install samba
chkconfig smb on

2、配置
cp /etc/samba/smb.conf  /etc/samba/smb.confbak
vi /etc/samba/smb.conf
[global]
diplay charset = gbk
unix charset = gbk
dos charset = gbk
workgroup = work
netbios name = work
server string = uc
security = user


[darwin]
comment = uc
path=/home/work/     
create mask = 0664
directory mask = 0775
writeable = yes
valid users = work
browseable = yes

#添加用户
smbpasswd -a work

3、启动

smbd -D
#查看进程是否启动
ps auxf | grep smbd  
netstat –npl   查看samba端口号,默认会使用139、445两个端口号

4、本地测试
smbclient -L 127.0.0.1 -U  work

mac:
command +k ; smb://ip_address

windows:
运行输入:\\Samba服务器的ip