LoginSignup
10
11

More than 5 years have passed since last update.

俺のminimalインストールしたCentOS7がこんなに手強いわけがない。

Last updated at Posted at 2015-05-13

社内検証用にCentOS7をminimalインストールした際に、自分の不手際で色々ハマった。
その時調べたNIC周りやらSSHできるようになるまでの設定メモ。
NetworkManagerは中々手強かった。net-tools入れたけど、慣れなければ…。

NW周り

NIC状態確認

[root@testsv ~]# nmcli device
デバイス  タイプ    状態      接続   
enp2s0    ethernet  接続済み  enp2s0 
eno1      ethernet  利用不可  --     
lo        loopback  管理無し  --     
[root@testsv ~]# 

もしくは nmcli d でもいいらしい。

IPアドレス確認

ちなみに下記はIP振った後。
(NIC裏っ返ってやがる…)

[root@testsv ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 28:92:4a:34:0f:76 brd ff:ff:ff:ff:ff:ff
       valid_lft forever preferred_lft forever
    inet6 fe80::2a92:4aff:fe34:f76/64 scope link 
       valid_lft forever preferred_lft forever
3: eno1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
    link/ether 28:92:4a:34:0f:77 brd ff:ff:ff:ff:ff:ff
[root@testsv ~]# nmcli c modify enp2s0 ipv4.address 192.168.4.15/24

IPv4でIPを振る。(IPとデフォゲ併せて設定)

[root@testsv ~]# nmcli connection modify enp2s0 ipv4.method manual ipv4.addresses 192.168.4.15/24 ipv4.gateway 192.168.4.241 

これも nmcli c mod の略式でいけるらしい。

リゾルバ設定。我慢できずにresolv.confに直書きした…。

[root@testsv ~]# echo "nameserver 8.8.8.8" > /etc/resolv.conf

後で見なおしたら、DNS設定がブランクに…。

[root@testsv ~]# nmcli --fields ipv4 connection show enp2s0
ipv4.method:                            manual
ipv4.dns:                               
ipv4.dns-search:                        
ipv4.addresses:                         192.168.4.15/24
ipv4.gateway:                           192.168.4.254
ipv4.routes:                            
ipv4.route-metric:                      -1
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
ipv4.never-default:                     no
ipv4.may-fail:                          no
[root@testsv ~]#

でも、curl http://google.comして、ちゃんと結果帰ってきたんです…。嘘じゃないんです…。
おそらく、NIC毎にリゾルバ設定できて、未設定ならresolv.conf見てくれるんじゃないか?と予想。(根拠ゼロ。)

本当はこっちが推奨らしい。

# リゾルバ設定
[root@testsv ~]# nmcli connection modify enp2s0 ipv4.dns 8.8.8.8

# IPとデフォゲとリゾルバまとめて設定。
[root@testsv ~]# nmcli connection modify enp2s0 ipv4.method manual ipv4.addresses 192.168.4.15/24 ipv4.gateway 192.168.4.254 ipv4.dns 8.8.8.8

NIC落とし上げ

ifdown/ifup相当?

[root@testsv ~]# nmcli connection down enp2s0
[root@testsv ~]# nmcli connection up enp2s0

SELinux

SELinux無効化。このあたりはRHEL6(CentOS6)までと変わらず。

定番だけど、新インストーラで適当にポチポチしてたら、無効化し忘れてた…。
sshdのポート番号変えた途端につながらないから、やっぱりそうだったよ…。
久しぶりにこんなミスしたわorz。

[root@testsv ~]# grep ^SELINUX= /etc/sysconfig/selinux 
SELINUX=enforcing
[root@testsv ~]# 
[root@testsv ~]# sed -ie 's|SELINUX=enforcing|SELINUX=disabled|g' /etc/sysconfig/selinux 
[root@testsv ~]# grep ^SELINUX= /etc/sysconfig/selinux 
SELINUX=disabled
[root@testsv ~]# 

Permisiveにするのも相変わらず。

[root@testsv ~]# setenforce 0 
[root@testsv ~]# getenforce 
Disabled
[root@testsv ~]# 

firewalld、iptables周り

新機能のfirewalldの自動起動をOFFにしちゃう。

firewalldはiptablesの代替。内部的にiptablesを使っているらしい。
確か、「Openstack用とかにプログラムから操作しやすいよう、わざわざ新たに作った」
…みたいな話をOpenstack本書いている人から聞いた気がするw

[root@testsv ~]# systemctl disable firewalld
rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'
rm '/etc/systemd/system/basic.target.wants/firewalld.service'
[root@testsv ~]# 

自動起動OFFになったことを確認。

[root@testsv ~]# systemctl list-unit-files -t service |grep fire
firewalld.service                           disabled
[root@testsv ~]# 

慣れ親しんだiptablesに切り替えちゃえ。

起動!え…でき…ない!?

[root@testsv ~]# systemctl start iptables.service
Failed to issue method call: Unit iptables.service failed to load: No such file or directory.
[root@testsv ~]

どうやら、firewalldのバックエンドとして、iptablesの一部が入っているだけで、サービスとしては入っていないらしい。

[root@testsv ~]# rpm -qa |grep iptables
iptables-1.4.21-13.el7.x86_64
[root@testsv ~]# 
[root@testsv ~]# yum search iptables
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.tsukuba.wide.ad.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: ftp.tsukuba.wide.ad.jp
=========================================================================================================== N/S matched: iptables ===========================================================================================================
iptables-devel.i686 : Development package for iptables
iptables-devel.x86_64 : Development package for iptables
iptables-services.x86_64 : iptables and ip6tables services for iptables
iptables-utils.x86_64 : iptables and ip6tables services for iptables
iptables.i686 : Tools for managing Linux kernel packet filtering capabilities
iptables.x86_64 : Tools for managing Linux kernel packet filtering capabilities

  Name and summary matches only, use "search all" for everything.
[root@testsv ~]# 

iptables-serviceをインストールして起動。

[root@testsv ~]# systemctl start iptables.service
[root@testsv ~]# iptables -nL
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
[root@testsv ~]# 

でも、どうせ社内設置の検証サーバなのでflushしてしまうw

[root@testsv ~]# iptables -nL
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
[root@testsv ~]# 

それでも、一応自動起動は有効化しておくw

docker入れるかもしれんしね。

[root@testsv ~]# systemctl list-unit-files -t service |grep iptables
iptables.service                            disabled
[root@testsv ~]# 
[root@testsv ~]# systemctl enable iptables
ln -s '/usr/lib/systemd/system/iptables.service' '/etc/systemd/system/basic.target.wants/iptables.service'
[root@testsv ~]# systemctl list-unit-files -t service |grep iptables
iptables.service                            enabled
[root@testsv ~]# 

ここでOS再起動してSELinuxの無効化を反映し、無事SSHできることを確認。
RHEL6までと比べると、プログラマ寄りの設定方法になっている気がする。
早いうちにsystemdに慣れておかないと、本当にやばそうだ…。

10
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
11