centos 网络自动连接(centos7ssh连接不上)
CentOS7mount网络磁盘的详细步骤
systemctl disable firewalld
systemctl stop firewalld
systemctl mask firewalld
vi/etc/iscsi/initiatorname.iscsi
InitiatorName= iqn.************;【注:eg:iqn.2017-09.com.centos:client1】
1.安装target
yum-y install targetcli
2.启动target服务
systemctl start target
3.设置开机自启动
systemctl enable target
4.新建分区
eg:
fdisk/dev/sda==>回车,见下图
5.进入交互模式
targetcli
6.建立一个块存储
/>/backstores/block create netdisk1.disk/dev/sdb1【注:其中netdisk1为自定义名称】
7.配置ISCSI target端的命名
/>/iscsi create iqn.2017-09.com.centos:server1【注:其中server1为自定义名称,且命名在同一子网中确保是唯一的】
8.创建ACL允许ISCSI客户机连接
/>/iscsi/iqn.2017-09.com.example:server1/tpg1/acls create iqn.2017-09.com.example:client1【注:其中server1为服务端,client1为客户端名称】
9.创建lun(target块设备的逻辑单元)
/>/iscsi/iqn.2017-03.com.example:server1/tpg1/luns create/backstores/block/netdisk1.disk
10.配置验证用户名和密码
/>cd/iscsi/iqn.2017-03.com.example:disk1/tpg1/acls/iqn.2017-03.com.example:client1
/>set auth userid=username
/>set auth password=password
11.配置完成后查看配置信息,并退出
/>cd/
/>ls
/>exit
1.安装ISCSI Initiator
# yum-y install iscsi-initiator-utils
2.配置ISCSI Initiator的名称
# vi/etc/iscsi/initiatorname.iscsi【注:此处InitiatorName必须与服务端配置的ACL允许ISCSI客户机连接的名称一致,且与上面的server端的配置相互配合】
3.修改ISCSI Initiator的配置文件
# vi/etc/iscsi/iscsid.conf
【注:node.session.auth.username为存储服务端set auth userid=username配置的username,node.session.auth.password= password为存储服务器端set auth password=password配置的password】
4.查找ISCSI设备
# iscsiadm-m discovery-t sendtargets-p 192.168.**.**
5.链接ISCSI设备
# iscsiadm-m node--login【注:如果登录一直失败的话,可以尝试重新启动下面两个服务:service iscsi stop; service iscsid stop; service iscsi start; service iscsid start;】
6.查看系统磁盘的信息
# fdisk-l
7.格式化磁盘
mkfs-t ext4/dev/sda
8.mount到指定的位置
mount/dev/sda/root/iscsi
9.设置开机自动连接ISCSI设备
# iscsiadm-m node-T iqn.2017-03.com.example:disk1-p192.168.**.**:3260-o update-n node.startup-v automatic【注:提到的名字与IP均为target端的】
10.设置开机挂载网络磁盘
开机挂载:采用写入fstab方式开启启动挂载磁盘
获取磁盘UUID:# blkid/dev/sda
编辑fstab:# vi/etc/fstab
添加配置:UUID=9f122014-071a-4416-b40f-ece882285b2b /mnt/iscsi ext4 defaults,_netdev 0 0
【说明】
UUID=ba7925cc-9bfb-4238-984d-999e18d592e8:磁盘UUID,代表磁盘
/mnt/iscs:代表挂载路径,根据实际灵活变动。
ext4:代表文件系统,根据实际灵活变动。
_netdev:代表该挂载的磁盘分区为网络磁盘分区。(在网络服务启动之后再去mount磁盘,若果不加的话,会使机器无法启动!!!!)
centos网络配置方法手动设置自动获取
不知道为什么最近一段时间网络特别的慢,还老是断,断的时候,局域网都连不上,当我手动设置一下ip后就可以了,搞得我很无语。下面是2种设置网络连接的方法,在说怎么设置前,一定要做好备份工作,特别是对于新手来说,如果修改的地方多了,你也会搞晕的,所以修改一个文件前一定要备份
一,修改文件来设置网络连接
1,自动获取IP的方法
自动获取根4个文件有关系
a),/etc/sysconfig/network-scripts/ifcfg-eth0
[zhangy@localhost network-scripts]$ cat ifcfg-eth0
# Marvell Technology Group Ltd. 88E8039 PCI-E Fast Ethernet Controller
DEVICE=eth0//由eth0来启动
BOOTPROTO=dhcp//获取IP的方式是自动获取,static是固定IP,none是手动
HWADDR=00:16:D3:A2:F6:09//网卡的物理地址
IPV6INIT=yes//是否支持IP6
IPV6_AUTOCONF=yes//IP6是否自动配置
ONBOOT=yes//启动时网络接口是否有效
b),/etc/sysconfig/network
[zhangy@localhost network-scripts]$ cat/etc/sysconfig/network
NETWORKING=yes//网络是否可用
NETWORKING_IPV6=yes
HOSTNAME=localhost.localdomain//主机名,主机名在/etc/hosts里面配置
c),/etc/hosts
[zhangy@localhost network-scripts]$ cat/etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost//根/etc/resolv.conf中search要对应,localhost.localdomain
::1 localhost6.localdomain6 localhost6
d),/etc/resolv.conf
[zhangy@localhost network-scripts]$ cat/etc/resolv.conf
; generated by/sbin/dhclient-script
nameserver 192.168.1.1//DNS服务器对应的IP
search localdomain//搜索要找的域名,在/etc/hosts里面设定的有
2,手动设定
手动设定只要修改三个文件就可以了
a),/etc/sysconfig/network
[zhangy@localhost network-scripts]$ cat/etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
#HOSTNAME=localhost.localdomain//为什么要把主机名注释掉,一般先解析主机名或者域名,再解析DNS
GATEWAY=192.168.1.1//加上网关
b),/etc/sysconfig/network-scripts/ifcfg-eth0
[zhangy@localhost network-scripts]$ cat ifcfg-eth0
# Marvell Technology Group Ltd. 88E8039 PCI-E Fast Ethernet Controller
DEVICE=eth0
BOOTPROTO=none//启动为手动
BROADCAST=192.168.1.255
HWADDR=00:16:D3:A2:F6:09
IPADDR=192.168.1.108//设置的IP
NETMASK=255.255.255.0//子网掩码
NETWORK=192.168.1.0
IPV6INIT=yes
IPV6_AUTOCONF=yes
ONBOOT=yes
TYPE=Ethernet//网络类型
c),/etc/resolv.conf
[zhangy@localhost network-scripts]$ cat/etc/resolv.conf
#; generated by/sbin/dhclient-script
#nameserver 192.168.1.1
#search localdomain
nameserver 116.228.111.118//加上主DNS
nameserver 180.168.255.18//加上次DNS
二,命令方法
netconfig是网络管理工具,RH装完机后,系统中就会有netconfig。虽然centos也是由RH演化来的,但是没有啊。不过没关系我们可能自己来装。
[zhangy@localhost download]$ wget
[zhangy@localhost download]$ rpm-ivh netconfig-0.8.24-1.2.2.1.i386.rpm
error: can't create transaction lock on/var/lib/rpm/__db.000
[zhangy@localhost download]$ su root//别忘了要用root账户,不然就会报上面的错误
口令:
[root@localhost download]# rpm-ivh netconfig-0.8.24-1.2.2.1.i386.rpm
Preparing...########################################### [100%]
1:netconfig########################################### [100%]
[root@localhost download]# whereis netconfig//查看一下netconfig在什么地方
netconfig:/usr/sbin/netconfig
复制代码代码如下:
[root@localhost]# netconfig--help
--bootproto=(dhcp|bootp|none) Boot protocol to use//获取IP的方式,dhcp是自,bootp固定IP,none手动
--gateway=STRING Network gateway//指定网关
--ip=STRING IP address//指定IP地址
--nameserver=STRING Nameserver//指定DNS
--netmask=STRING Netmask//指定子网掩码
--hostname=STRING Hostname//指定主机名
--domain=STRING Domain name//指定域名
-d,--device=STRING Network device//指定网络设备
--nodns No DNS lookups//没有DNS查询
--hwaddr=STRING Ethernet hardware address//指定网卡的物理地址
--description=STRING Description of the device//描述
Help options:
-?,--help Show this help message
--usage Display brief usage message
1,自动获取IP
[root@localhost download]#/usr/sbin/netconfig-d eth0--bootproto=dhcp
2,手动设置IP
[root@localhost download]#/usr/sbin/netconfig-d eth0--bootproto=none--ip=192.168.1.108--netmask=255.255.255.0--gateway=192.168.1.1--nameserver=116.228.111.118
三,配置中遇到的一些问题
1,重启网络不起作用
service network restart重启后还是无法连接网络,我可以确定我配置的没问题,重新启动一下电脑就可以了。
2,备份ifcfg-eth0文件的时候要注意,前面不要带有ifcfg-eth0
ifcfg-eth0
上图中我把自动获取IP的配置文件ifcfg-eth0作了备份,名子为ifcfg-eth0_dhcp,重新启动网络的时候,这个文件依然被执行了,开始的时候,我并没注意到这一点,等我ifconfig查看网络的时候,发现我做的修改根本没有启作用,并且/etc/resolv.conf里面做的修改又被盖了。所以备份的时候,前面不要带有ifcfg-eth0
CentOS设置开机启动服务及自动联网的方法
可以修改开机启动配置只需修改:
vi/etc/sysconfig/network-scripts/ifcfg-eth0
如图
文件,把ONBOOT=”no”改为yes,下一次就不用手动连接了。
DEVICE=”eth0”:接口
HWADDR=”00:00:00:00:00:00”:硬件地址
NM_CONTROLLED意思是network manger的参数,yes是实时生效,修改后无需要重启网卡立即生效。
ONBOOT=”yes”:是指明在系统启动时是否激活网卡,只有在激活状态的网卡才能去连接网络,进行网络通讯