クラウド環境が多いのでそんなに設定することはないけれど。
ホスト名設定
# hostnamectl set-hostname web1.example.com
デバイス確認
# nmcli d DEVICE TYPE STATE CONNECTION ens160 ethernet connected ens160 lo loopback unmanaged --
# vi /etc/sysconfig/network-scripts/ifcfg-ens160 TYPE=Ethernet BOOTPROTO=none ←設定 DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens160 UUID=c51b65c1-4e8c-4a95-acc4-084ead9878be DEVICE=ens160 ONBOOT=yes ←設定 DNS1=192.168.11.1 ←設定 IPADDR=192.168.11.121 ←設定 PREFIX=24 GATEWAY=192.168.11.1 ←設定 IPV6_PEERDNS=yes IPV6_PEERROUTES=yes
# systemctl enable network
# systemctl start network
# systemctl enable NetworkManager
# systemctl restart NetworkManager
# vi /etc/sysconfig/selinux SELINUX=enforcing ↓変更 SELINUX=disabled
# reboot
もくじ
コマンドラインで設定しても良い
デバイス確認
# nmcli d DEVICE TYPE STATE CONNECTION ens160 ethernet connected ens160 lo loopback unmanaged --
固定IPv4アドレス設定 ⇒ nmcli ~ IPアドレス
# nmcli c modify ens160 ipv4.addresses 192.168.11.121/24
デフォルトゲートウェイ設定
# nmcli c modify ens160 ipv4.gateway 192.168.11.1
DNS設定
# nmcli c modify ens160 ipv4.dns 192.168.11.1
IP固定割り当てに設定 (DHCP は “auto”)
# nmcli c modify ens160 ipv4.method manual
インターフェースを再起動して設定を反映
# nmcli c down ens160; nmcli c up ens160 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1)
設定確認
# nmcli d show ens160 GENERAL.デバイス: ens160 GENERAL.タイプ: ethernet GENERAL.ハードウェアアドレス: 00:0C:29:BB:CF:2E GENERAL.MTU: 1500 GENERAL.状態: 100 (接続済み) GENERAL.接続: ens160 GENERAL.CON パス: /org/freedesktop/NetworkManager/ActiveConnection/0 WIRED-PROPERTIES.キャリア: オン IP4.アドレス[1]: 192.168.11.121/24 IP4.ゲートウェイ: 192.168.11.1 IP4.DNS[1]: 192.168.11.1 IP6.アドレス[1]: fe80::634a:d911:bbc3:96d6/64
IP6.ゲートウェイ:
接続確認
# ip addr show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1 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: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:bb:cf:2e brd ff:ff:ff:ff:ff:ff inet 192.168.11.121/24 brd 192.168.11.255 scope global ens160 valid_lft forever preferred_lft forever inet6 fe80::634a:d911:bbc3:96d6/64 scope link valid_lft forever preferred_lft forever
# systemctl enable network
# systemctl start network
# systemctl enable NetworkManager
# systemctl restart NetworkManager
# vi /etc/sysconfig/selinux SELINUX=enforcing ↓変更 SELINUX=disabled
# reboot
Firewalld設定
現状の確認
# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: eth0 sources: services: dhcpv6-client ssh ports: protocols: masquerade: no forward-ports: sourceports: icmp-blocks: rich rules:
# firewall-cmd --list-service --zone=public dhcpv6-client ssh
SSH # firewall-cmd --permanent --add-port=22/tcp --zone=public --permanent # firewall-cmd --permanent --add-port=xxx22/tcp --zone=public --permanent HTTP, HTTPS # firewall-cmd --permanent --add-port=80/tcp --zone=public --permanent # firewall-cmd --permanent --add-port=443/tcp --zone=public --permanent FTP # firewall-cmd --permanent --add-port=20/tcp --zone=public --permanent # firewall-cmd --permanent --add-port=21/tcp --zone=public --permanent # firewall-cmd --permanent --add-port=50000-50030/tcp --zone=public --permanent
有効な設定を確認
# firewall-cmd --list-service --zone=public --permanent dhcpv6-client ssh
# firewall-cmd --list-port --zone=public --permanent 443/tcp 80/tcp 50000-50030/tcp 20/tcp 21/tcp xxx22/tcp
設定を反映させる
# firewall-cmd --reload
有効なゾーンの確認
# firewall-cmd --get-active-zones public interfaces: eth0
■MySQLの外部接続許可設定
# firewall-cmd --permanent --new-zone=mysql # firewall-cmd --reload # firewall-cmd --permanent --zone=mysql --set-target=ACCEPT # firewall-cmd --permanent --zone=mysql --add-service=mysql # firewall-cmd --permanent --zone=mysql --add-source=153.xxx.yyy.160/32 # firewall-cmd --reload
# firewall-cmd --get-active-zones public interfaces: eth0 mysql sources: 153.xxx.yyy.160/32
# systemctl reload firewalld
# vi /etc/my.cnf bind-address = 0.0.0.0
# netstat -antu Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:55522 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN (略)
# mysql -u root mysql> grant all privileges on DB名.* to DBユーザ名@"%" identified by 'パスワード'; mysql> exit
ゾーンの削除
# firewall-cmd --permanent --delete-zone=mysql
有効なゾーンの確認
# firewall-cmd --get-active-zones public interfaces: eth0
■一時的に遮断
# firewall-cmd --zone=drop --add-source=xxx.xxx.xxx.0/24 # firewall-cmd --list-all --zone=public firewall-cmd --add-rich-rule='rule family="ipv4" source address="192.168.0.0/24" port port="513-514" protocol="tcp" \