How to determine dynamic IP automatically - SAP system insta

Dear colleges,

I am NOT a specialist, so I am sorry whether this is a very basic doubt. So I will need your kindly help on that !

I am using my machine/server (with SAP installed) in order to teach SAP on-line, so every time before to startup the SAP system I need to check my IP number (dynamic) via “ifconfig” command and then I open the file “etc/hosts” and change the IP number manually. However when the IP changes again (everyday) I need to shutdown the SAP system & machine to recognize the new IP and then to change the new IP number in the file “hosts” again and again…

Therefore, I wonder whether there is a way to recognize the new IP automatically without shutdown the SAP system & machine as well as do not change the IP in the file “hosts” manually ?

I heard something regarding DHCP resource, but I have no idea whether it is the a solution as well as how to configure that. On the other, I also heard that I could “deactivate” the DHCP and put all machines as a manual IP, but unfortunately DHCP deactivation is not able in the IP configuration.

Well, not sure whether I could give you all necessary details, and I kindly request a very basic step by step once I am very new in this operational system.

cheers,

flmarcilio wrote:
[color=blue]

Well, not sure whether I could give you all necessary details, and I
kindly request a very basic step by step once I am very new in this
operational system.[/color]

Perhaps it would help us of you could provide some more details…

A server usually has a static IP address which can be configured using
YaSt. Even if you are using DHCP, once your server has its IP address,
it should keep it. What is causing the IP address to change every day?


Kevin Boyle - Knowledge Partner
If you find this post helpful and are logged into the web interface,
please show your appreciation and click on the star below this post.
Thank you.

Hi,

to detect the inet (IP v4) address of an interface via script, a quickly hacked sequence could be:

ip addr show dev eth0 |awk -e '/ inet / { print gensub( /inet ([0-9]*\\.[0-9]*\\.[0-9]*\\.[0-9]*).*/, "\\\\1", "g") }'

(assuming the interface in question is eth0 - please substitute accordingly)

To replace the according entry in your /etc/hosts file, you could use “sed” to inline replace the IP address.

Here’ a quick hack for a bash script - I’ve called it “dyn2hosts” and it takes three optional parameters: the network device, the host name to replace and the file name. So if you want to replace the IP address of entry “myhost.company.com” in /etc/hosts with the IP address of device ppp0, you’d call it by “dyn2hosts ppp0 myhost.company.com”:

[CODE]#!/bin/bash

dynamically replace the IP part of the named /etc/hosts entry with the

current IP address of the named interface

you can change the defaults here, but I’d recommend to always specify proper values for DEV and FQDN via script parameters 1 and 2.

DEV=“eth0”
FQDN=“myhost.company.com
ETCHOSTS="/etc/hosts"

if [ ! -z “$1” ] ; then
DEV=$1
fi

if [ ! -z “$2” ] ; then
FQDN=$2
fi

if [ ! -z “$3” ] ; then
ETCHOSTS=$3
fi

if [ -w $ETCHOSTS ] ; then
# does the file contain the given host name?
grep “$FQDN” $ETCHOSTS > /dev/null

    if [ $? -eq 0 ] ; then
            IP=$(echo $(ip addr show dev $DEV 2> /dev/null | awk -e '/ inet / { print gensub( /inet ([0-9]*\\.[0-9]*\\.[0-9]*\\.[0-9]*).*/, "\\\\1", "g") }'))

            if [ ! -z "$IP" ] ; then
                    sed -i "/$FQDN/s/^[0-9]*\\.[0-9]*\\.[0-9]*\\.[0-9]*/$IP/" $ETCHOSTS

                    if [ $? -eq 0 ] ; then
                            echo "$0: Substituted IP $IP for host $FQDN in file $ETCHOSTS."
                            rc=0
                    else
                            echo "$0: Could not substitute IP $IP for host $FQDN in file $ETCHOSTS. Failed."
                            rc=4
                    fi
            else
                    echo "$0: Could not determine IP address of device $DEV. Failed."
                    rc=3
            fi
    else
            echo "$0: File $ETCHOSTS does not contain entry for $FQDN. Failed."
            rc=2
    fi

else
echo “$0: File $ETCHOSTS either doesn’t exist or isn’t writable to us. Failed.”
rc=1
fi

exit $rc
[/CODE]

Of course, use the script at your own risk - it’s nothing more than a quick hack done during coffee break :[

Regards,
J

[QUOTE=KBOYLE;50651]flmarcilio wrote:
[color=blue]

Well, not sure whether I could give you all necessary details, and I
kindly request a very basic step by step once I am very new in this
operational system.[/color]

Perhaps it would help us of you could provide some more details…

A server usually has a static IP address which can be configured using
YaSt. Even if you are using DHCP, once your server has its IP address,
it should keep it. What is causing the IP address to change every day?


Kevin Boyle - Knowledge Partner
If you find this post helpful and are logged into the web interface,
please show your appreciation and click on the star below this post.
Thank you.[/QUOTE]

Hi Kevin, first of all thanks for your help !

Well, as my machine/server is in my home so I am using an internet with dynamic IP as in Brazil only legal entity could have fixed IP (this is my config address 192.168.1.1), it means that everyday the IP changes automatically (for example from 192.168.1.XX to 192.168.1.YY) I supose due to the contracted rules I have made with the BR telecom company who provides the internet service.

So, I am trying to find out an easy way to recognize this new dynamic IP automatically as soon as it has been changed, quite similar what happen with my others machines like cellphone, dell computer (windows), etc…, these machines can recognize the new IP automatically.

Hi,

So, I am trying to find out an easy way to recognize this new dynamic IP automatically as soon as it has been changed

actually I’m wondering if you’re trying to solve the right problem, but that’s likely due to a mis-understanding on my side.

If it’s just that the SAP server needs to reach itself by name, then you might try to point the DNS name at the loopback address, by placing the dns name on the /etc/hosts line for 127.0.0.1. That way, any process on that server that’s trying to contact the given DNS name will go via the loopback interface, with its constant IP address.

Or do you actually need to reach the IP address, i.e. because the server processes are listening on that interface only? /etc/hosts entries are often cached at the application level, so changing /etc/hosts may in fact need a restart of the server processes.

Another issue that is not fully clear to me is if the SAP server is actually able to get its new IP address when your provides re-assigns it (“However when the IP changes again (everyday) I need to shutdown the […] machine to recognize the new IP”). If that is true, I’d need more details on how the server connects to the Internet and receives its address.

If above solution (pointing to 127.0.0.1) does not help, please let us know more technical details so we can get down to the root cause and help you find a solution :slight_smile:

Regards,
J

flmarcilio wrote:
[color=blue]

Hi Kevin, first of all thanks for your help[/color]

You’re very welcome.

I see that Jens (jmozdzen) has a few suggestions that may help…

I see two different ways to resolve your problem:

  • find a way to deal with a constantly changing IP address
  • Find a way to prevent the IP address from constantly changing.

Most ISPs provide their customers a dynamic IP address but often this
is a PUBLIC dynamic IP address that permits traffic to be routed
across the Internet. When customers have multiple devices they wish to
use and the ISP provides only a single dynamic public IP address, a
router is used to assign a private IP address, often on the
192.168.1.0 network, to each of the local devices. The router
translates the assigned private IP address (192.168.1.x) to the public
IP address to allow each device to access the Internet using the one
public IP address.

I suspect this is what you have as you mention that your cellphone can
recognise a new IP address automatically. Since cellphones usually can
connect to a WI-FI network, this suggests that you have a router
configured to provide a local 192.168.1.0 network that can be used by
both wired and wireless devices. If this is indeed the case, the router
should have a web interface so you can configure the router. Most
routers let you configure the address of the private network, whether
or not DHCP addresses will be provided, and often you can specify
static IP addresses for specific devices.

If you can provide the make/model of your router, perhaps I could
provide additional information.

If it is impossible to configure a static IP address on your router for
your server, and you cannot make SAP work with the loopback address as
Jens suggested, you should still be able to configure a static IP
address on your server for SAP even if the router assigns your server a
dynamic IP address. This is not an ideal solution because it requires
additional server configuration so let’s look at what other solutions
are available first.


Kevin Boyle - Knowledge Partner
If you find this post helpful and are logged into the web interface,
please show your appreciation and click on the star below this post.
Thank you.

[QUOTE=KBOYLE;50674]flmarcilio wrote:
[color=blue]

Hi Kevin, first of all thanks for your help[/color]

You’re very welcome.

I see that Jens (jmozdzen) has a few suggestions that may help…

I see two different ways to resolve your problem:

  • find a way to deal with a constantly changing IP address
  • Find a way to prevent the IP address from constantly changing.

Most ISPs provide their customers a dynamic IP address but often this
is a PUBLIC dynamic IP address that permits traffic to be routed
across the Internet. When customers have multiple devices they wish to
use and the ISP provides only a single dynamic public IP address, a
router is used to assign a private IP address, often on the
192.168.1.0 network, to each of the local devices. The router
translates the assigned private IP address (192.168.1.x) to the public
IP address to allow each device to access the Internet using the one
public IP address.

I suspect this is what you have as you mention that your cellphone can
recognise a new IP address automatically. Since cellphones usually can
connect to a WI-FI network, this suggests that you have a router
configured to provide a local 192.168.1.0 network that can be used by
both wired and wireless devices. If this is indeed the case, the router
should have a web interface so you can configure the router. Most
routers let you configure the address of the private network, whether
or not DHCP addresses will be provided, and often you can specify
static IP addresses for specific devices.

If you can provide the make/model of your router, perhaps I could
provide additional information.

If it is impossible to configure a static IP address on your router for
your server, and you cannot make SAP work with the loopback address as
Jens suggested, you should still be able to configure a static IP
address on your server for SAP even if the router assigns your server a
dynamic IP address. This is not an ideal solution because it requires
additional server configuration so let’s look at what other solutions
are available first.


Kevin Boyle - Knowledge Partner
If you find this post helpful and are logged into the web interface,
please show your appreciation and click on the star below this post.
Thank you.[/QUOTE]

Dears Jens (jmozdzen) and Kevin Boyle

Thank you very much for both of you to have patient in order to guide me with a lot of details.

Well, I will try an option (not sure if it makes sense) in order to use my NOIP host name (fixed IP address) and then assign it to my router DDNS config. So therefore, I will fix this host name in the HOSTS file - SAP server which means it will be fixed even though the public IP address will be changed afterwards. On the other way, what I have been noticing is something related to IP conflict when it is changed, so I expect if I fix a NOIP host name perhaps it could avoid this conflict and fix my issue.

Whether my option described will not work, then I come back to you guys for deep dive into your guidance.

Well, again as I am very new in this infra-structure & network issues as well as Suse - Linux world, I am doing my best to share as much details as I can.

cheers,

/Flavio Marcilio

flmarcilio wrote:
[color=blue]

Well, again as I am very new in this infra-structure & network issues
as well as Suse - Linux world, I am doing my best to share as much
details as I can.[/color]

When you are ready, we are here to help any way we can.


Kevin Boyle - Knowledge Partner
If you find this post helpful and are logged into the web interface,
please show your appreciation and click on the star below this post.
Thank you.