VirtualBox + CentOS のネットワークの設定

Shunsuke Sawada

マックをMountain Lionにしたせいか、
VirtualBoxをアップデートしたせいか、
ローカル環境の設定がおかしくなってしまっていた。。

つくったアプリからメールを送ろうとするとエラー。
php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
とかね。

でも他のページは表示はできてたから、こりゃVirtualBoxかCentOSの設定だなと。
Pingも飛ばなかった。。。あれー。ということで、週末ずっとググってました。

もうなにがなんだか分からなくなるので、
以前にやったこの設定はリセット。落ち着いたらまたやろう。

VirtualBoxでローカル環境つくる時に必要なお作法

ローカル環境作った時のことを思い出せ!

•ファイヤーウォール(iptables)をオフにする。
•SELinuxをOFFにする

これについてはDotinstallが初心者にはとても分かりやすい。
http://dotinstall.com/lessons/basic_local_development/2215
http://dotinstall.com/lessons/basic_local_development/2216

[googlead]

ネットワークの設定

詳しい設定は、いろいろググれば出てくるので手がかりだけ。

ホスト名、ゲートウェイ、IPアドレスの設定
vi /etc/sysconfig/network
vi /etc/sysconfig/network-scripts/ifcfg-eth0
vi /etc/resolv.conf

その他つかったコマンド。

arp -a
ifconfig
route
ping yahoo.co.jp
ping 8.8.8.8
service network restart

Virtual hostの設定

これはCentOSとかではないんだけど、うっかりミスでした。
ディレクトリ構成変えたの忘れてて、設定が古いままになっていたので修正。
メールが送れないのはこれも影響してました。

1
2
3
4
5
6
7
8
9
10
11
<VirtualHost *:80>
  ServerName xxxxxxxx.com
  DocumentRoot "/var/www/html/xxxxxxxx.com"
  DirectoryIndex index.html index.php
  ErrorLog /var/log/httpd/xxxxxxxx.com_error_log
  CustomLog /var/log/httpd/xxxxxxxx.com_access_log combined
  AddDefaultCharset UTF-8
  <Directory "/var/www/html/xxxxxxxx.com">
    AllowOverride All
  </Directory>
</VirtualHost>

なんとか、週末中に終わったので、勝利のビール。
こんなのばっかりで全然開発すすまねー。
でもやんなきゃ進まないので、少しずつ。少しずつです。

参考サイト

http://d.hatena.ne.jp/bojovs/20081020/1224429418
http://www.ashibit.net/blog/linux/519/
http://d.hatena.ne.jp/seto-san/20090617/1245202016
http://winlinux.blog105.fc2.com/blog-entry-212.html

- - 追記 - -

参考
https://users.miraclelinux.com/technet/document/linux/training/1_5_1.html

MAC 設定

vi /etc/sysconfig/network-scripts/ifcfg-eth0

1
2
3
4
5
6
7
DEVICE=eth0
BOOTPROTO=no
BROADCAST=192.168.1.255
IPADDR=192.168.0.15
HWADDR=08:00:27:35:37:31
ONBOOT=yes
GATEWAY=192.168.0.1

vi /etc/resolv.conf

1
nameserver 192.168.0.1

vi /etc/sysconfig/network

1
2
3
4
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=localhost.localdomain
GATEWAY=192.168.0.1
Shunsuke Sawada

おすすめの記事

CakePHP 2.x JSヘルパーでajax通信(ajax helperは使わない)
20
Rails4でQiita投稿ボタンをつくった
18
紙のデザイナーがウェブ開発できるようになるまでに必要なこと
451