DoyleChris
Posts: 32
Joined: Wed Nov 20, 2013 10:04 pm

Give a Static IP if no Dynamic IP

Fri Mar 25, 2016 1:34 pm

I am setting up 2 RPI's i have a A version and a RPi 2 and im trying to set it up so if im connected to my network i get a ip for it from my router.

But if im not on my home network I would like it to get a static ip so i can connect to it.

Is there anyway of doing that in the /etc/interfaces.

DoyleChris
Posts: 32
Joined: Wed Nov 20, 2013 10:04 pm

Re: Give a Static IP if no Dynamic IP

Fri Mar 25, 2016 2:06 pm

Found that answer here viewtopic.php?f=66&t=140252

all i did was added this to the /etc/dhcpcd.conf

interface eth0
fallback nodhcp

profile nodhcp
static ip_address=192.168.1.***/24

*** where the ip is the want you want to connect to.

gdt
Posts: 85
Joined: Thu Jul 19, 2012 10:19 am

Re: Give a Static IP if no Dynamic IP

Tue Mar 29, 2016 10:46 am

If you intend to do this for a lot of machines (say a whole classroom) then your need might be better met with a link-local address and a ZeroConf mDNS advertisement.

1) The easiest way to get a link local address is to activate IPv6. Remove the blacklisting in /etc/modprobe.d/ipv6.conf and reboot.

2) To multicast-advertise the DNS service for ssh into the local subnet install Avahi with "sudo apt-get install avahi-daemon"; add the file /etc/avahi/services/ssh.service containing

Code: Select all

<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
 <name replace-wildcards="yes">%h</name>
 <service>
  <type>_ssh._tcp</type>
  <port>22</port>
 </service>
</service-group>
then activate this with "sudo avahi-daemon --reload".

3) Add multicast DNS to the name services with "sudo apt-get install libnss-mdns" and alter the "hosts" line in /etc/nsswitch.conf to

Code: Select all

hosts: files mdns_minimal [NOTFOUND=return] dns
Now if your computer is named "fred" and you are on the same subnet as the computer you can simply say "ssh fred.local". The addressing and other details are taken care of as part of IPv6's automatic configuration. In the absence of reachability to the global IPv6 internet the link local address will be the only IPv6 address on the interface.

Modify any access control lists set with iptables to include IPv6 (see ip6tables).

Return to “Networking and servers”