Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have 3 IPs in my server, i want use them to increase twitter API limits.

How to set a different ip for a directory in centos 6.1 httpd.conf (apache 2.3.1)

I added these line in the bottom of httpd.conf

<VirtualHost NEW IP:80>
    ServerName mydomain.com/subdir
    ServerAlias www.mydomain.com/subdir
    DocumentRoot /var/www/html/subdir
    <directory "/var/www/html/subdir">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Allow from all
    </directory>
</VirtualHost>

But when I test /var/www/html/subdir/index.php with code

<?php
function get_server_ip() {
    if (isset($_SERVER)) {
        if($_SERVER['SERVER_ADDR']) {
            $server_ip = $_SERVER['SERVER_ADDR'];
        }else{
            $server_ip = $_SERVER['LOCAL_ADDR'];
        }
    }else {
        $server_ip = getenv('SERVER_ADDR');
    }
    return $server_ip;
}
echo get_server_ip();
?>

it still return OLD IP (default ip for my server). So is it possible and how? If it couldn't, how to use 3 IPs to increase twitter API limits.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Doing an apache configurations is not enough. To make it work you have to configure multiple IP Address into your Centos (RedHat) box.

Assuming that you have only one phisical network interface eth0, then you have this file that contain all the relevant parameters :

$ cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
BROADCAST=192.168.0.255
IPADDR=192.168.1.1
NETMASK=255.255.255.0
NETWORK=192.168.1.0
ONBOOT=yes

(This is a sample statical ip configuration for IP=192.168.1.1, yours may and will vary)

All this is explained here: CENTOS-Network Configuration Files and CENTOS-Interface Configuration Files

To assign another IP to the same phisical network interface eth0 do this (as root) :

$ cd /etc/sysconfig/network-scripts/
$ cp ifcfg-eth0 ifcfg-eth0:1
$ vi ifcfg-eth0:1

and then change IPADDR to the new file (and check/change all the other parameters)

You can do the same for third new IP doing cp ifcfg-eth0 ifcfg-eth0:2 and edit the file.

Then you have to restar network to apply changes (stop apache before):

$ service network restart

Check the new config :

$ ifconfig 

You will see listed the interface configuration for eth1 , eth1:1 , eth1:2 (and probabily more iterfaces like lo -> loopback )

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.